Swift protocol forcing the Equableable protocol

I have 2 protocols. I need the first (NameProtocol) to enforce the Equatable protocol. While another class (BuilderProtocol) has a method that returns the first (NameProtocol).

public protocol NameProtocol : Equatable {
    var name: String { get }
}

public protocol BuilderProtocol {
    func build() -> NameProtocol? // Compiler error
    init()
}

Compiler error: "The Protocol" NameProtocol "can only be used as a general restriction, since it has its own or related requirements like"

I need to return a build () object to return an object corresponding to NameProtocol, and on which I can define ==

Is there any way to make this work?

thank


If using typealias in BuilderProtocol can I make an array declaration work?

public protocol OtherRelatedProtocol {
    var allNames : Array<NameProtocol> { get }
}

Conclusion

I will remove Equatable and implement the isEqual method.

public protocol NameProtocol {
    func isEqual(nameable: NameProtocol) -> Bool
    var name: String { get }
}
+4
1

Java #, Swift . , :

protocol Foo {
    func compareWith(foo: Self)
}

, , compareWith, ( Foo).

, "Self ", Equatable ( operator==, Self). , : .

. ProtocolBuilder , NameProtocol.

public protocol NameProtocol : Equatable {
    var name: String { get }
}

public protocol BuilderProtocol {
    typealias T: NameProtocol
    func build() -> T?
    init()
}
+3

Source: https://habr.com/ru/post/1584397/