[swift-users] Superclass constraint cannot depend on type parameter
Jon Shier
jon at jonshier.com
Wed Mar 9 14:48:50 CST 2016
Swifters:
I just encountered the error “Superclass constraint ‘RepeatableNetworkOperation<U>’ cannot depend on a type parameter” on this definition:
class RepeatedNetworkOperation<T, U where U: Decodable, U == U.DecodedType, U: Repeatable, T: RepeatableNetworkOperation<U>>: RepeatedOperation<T> { … }
where the relevant other classes are defined as:
class InterruptibleNetworkOperation<T: Decodable where T == T.DecodedType>: GroupOperation { … }
class RepeatedOperation<T where T: NSOperation>: GroupOperation { … }
class RepeatableNetworkOperation<T where T: Decodable, T == T.DecodedType, T: Repeatable>: InterruptibleNetworkOperation<T>, Repeatable { … }
I understand the error, but am I correct in thinking this is just a limitation of Swift’s current type and/or generics systems? I’m not a language theorist, but it seems perfectly reasonable that something like this should work. If it is just a limitation and not something I’m doing wrong, are there any suggestions for a workaround? The class I’m trying to write would really clean up my code.
Jon
More information about the swift-users
mailing list