Expanding to a restricted vocabulary conforming to the protocol
I am trying to create a protocol that allows any objects to be created using JSON NSData.
I am trying to create an extension for a dictionary [String: String] that conforms to this protocol. Unfortunately, for some reason the following code doesn't work:
public protocol InitializableWithData {
init(data: NSData?) throws
}
extension Dictionary: InitializableWithData where Key: String, Value: String {
public init(data: NSData?) {
self.init()
// Parse NSData into a [String: String]
}
}
I am getting the following error:
Extension of type 'Dictionary' with constraints cannot have an inheritance clause
I've also tried:
extension Dictionary: InitializableWithData where Key: NSString, Value: NSString {
public init(data: NSData?) {
self.init()
// Parse NSData into a [String: String]
}
}
Considering String is a struct but still it doesn't work.
+1
source to share
No one has answered this question yet
See similar questions:
or similar: