Swift related types in protocol with where clause?

Consider the following:

protocol SomeProtocol { typealias F: Foo typealias FB: FooBar where FB.Foo == F } 

But this does not compile, since we cannot put the where clause in typealias .

I need to skip something, as this can be easily done with type parameterization as follows:

 struct SomeStruct<F: Foo, FB: FooBar where FB.Foo == F> {} 

What is equivalent to where for associated type ?

+6
source share
1 answer

Parameterization of related types in protocols is currently not supported in Swift (2.1).

Although in this case you don’t even need a where clause for functionality. This is more a convenience you get where you can do this:

 func someFunc<T: SomeProtocol>(someProt: T, foo: TF) { ... } // Instead of this: func someFunc<T: SomeProtocol>(someProt: T, foo: T.FB.Foo) { ... } 
0
source

All Articles