Reputation: 2006
Given the following code:
protocol NetworkWire {
//some requirements
}
protocol EntityRESTRequest {
//some requirements
}
protocol OctupPromisable {
//some requirements
}
final class HTTPNetworkWire: NetworkWire, EntityRESTRequest, OctupPromisable {
//satisfies all requirements
}
I now create a func like so,
extension NSManagedObject {
func post<T where T:NetworkWire, T:EntityRESTRequest, T:OctupPromisable>(navigationalProperties: String, networkWireType: T.Type = HTTPNetworkWire) -> OctupPromisable {
//some logic with valid return
}
}
The compiler gives me an error on the post func saying,
Default Argument of HTTPNetworkWire.Type cannot be converted to type T.type
Any idea why this is? Although HTTPNetworkWire conforms to NetworkWire,EntityRESTRequest as well as OctupPromisable!
Any ideas will be appreciated. Running Xcode 7.1.1
Upvotes: 0
Views: 194
Reputation: 51911
You should use Protocol Composition without generics:
extension NSManagedObject {
func post(navigationalProperties: String, networkWireType: protocol<NetworkWire, EntityRESTRequest, OctupPromisable>.Type = HTTPNetworkWire.self) -> OctupPromisable {
//some logic with valid return
}
}
Upvotes: 2