I want to create a Convertible-like protocol and extend NSObject
subclasses to implement it. In particular:
protocol DataConvertible {
class func convertFromData(data:NSData) -> Self?
func data() -> NSData
}
I thought implementing would be as simple as:
extension UIImage : DataConvertible {
class func convertFromData(data:NSData) -> Self? {
let image : UIImage? = UIImage(data: data)
return image
}
func data() -> NSData {
return UIImagePNGRepresentation(self)
}
}
But this fails to compile with error 'UIImage' is not identical to 'Self'
. Am I missing something?
Is there another way to implement a protocol like this?