< and > do not match the protocol. This applies to types with types such as an array:
Array<T>
so you can write var a: Array<String> .
You want something else, the variable must be of type String and conform to the protocol
You can extend String using the protocol and add the necessary functions yourself.
Since your Optional protocol is empty, just write:
extension NSString: Optional {}
To create a write protocol in Swift:
protocol Optional {}
You can also create an Objective-C protocol.
You should not use the option because it is already gone, but since Swift has a namespace, it works. You could, of course, write something like this:
extension NSString: JsonOptProtocol {} protocol JsonOptProtocol {}
Documentation link .
source share