Check the following method definition:
func method<T,K>(protocol: K, object: T) where T:AnyObject, K:Protocol {
// Do stuff here
}
T
is anAnyObject
K
is aProtocol
Now I would like to add an additional constraint: the object of type T
must implement the protocol K
.
Something like this:
func method<T,K>(protocol: K, object: T) where T:AnyObject, K:Protocol, T:K {
// Do stuff here
}
Note the T:K
added in the where
clausule.
When I try this, I get the error:
Type 'T' constrained to a non-protocol, non-class type 'K'
Is this achievable somehow?