Why doesn\'t this Swift code compile?
protocol P { }
struct S: P { }
let arr:[P] = [ S() ]
extension Array where Element : P {
func test() -&g
If you extend CollectionType
protocol instead of Array
and constraint by protocol as a concrete type, you can rewrite the previous code as follows.
protocol P { }
struct S: P { }
let arr:[P] = [ S() ]
extension CollectionType where Generator.Element == P {
func test() -> [T] {
return []
}
}
let result : [S] = arr.test()