Reputation: 4760
I have been trying to find an answer to understand the "under the hook" or "technicalities" on whether or not the following code should be or not be avoided:
protocol Member {
var id: String: { get }
var name: String { get }
}
protocol RegularMember: Member {
var name: String { get }
...
}
RegularMember declares the same property name that Member also declares.
I have had this question always in my head and always assumed that it was bad practice but never got further than that.
Does anyone have different thoughts?
Upvotes: 0
Views: 52
Reputation: 534950
However, Xcode is not showing neither a warning nor an error.
Because it isn't wrong for protocol B that conforms to protocol A to repeat requirements from protocol A. Quite the contrary! It doesn't change the meaning of anything, and in fact, it's good practice stylistically because it can make your code more readable; the Swift Standard Library does it a lot.
Upvotes: 2