As expected, an associated type can be specified either in the protocol or in the conforming type(s).
So this compiles:
protocol Fooable {
typealias Bar = Int
}
struct SomeFoo : Fooable {
}As does this:
protocol Fooable {
typealias Bar
}
struct SomeFoo : Fooable {
typealias Bar = Int
}But for some reason associated types cannot be specified through a protocol extension, ie:
protocol Fooable {
typealias Bar
}
extension Fooable {
typealias Bar = Int
}
struct SomeFoo : Fooable { // Error: Type 'SomeFoo' does not conform to protocol 'Fooable'
}Is this a bug (Xcode 7 and Xcode 7.1 beta 2)?
(This is of course a bare bones example of the problem. In my actual use case the associated type is being derived from another type (rather than just being eg Int) and it makes more sense to specify that relationship in a protocol extension than repeating it in every concrete type.)