It seems to me that the answer is obvious, but I could not understand it, and for me this is a recurring problem. Basically I want to do something like this:
extension NSData {
convenience init(JSONObject: AnyObject) {
do {
self = try NSJSONSerialization.dataWithJSONObject(JSONObject, options: [])
}
catch {
self = nil
}
}
}
However, he will not allow me to simply assign meaning to myself. I do this all the time with enumerations, but that will not allow me to do this with classes. Is there a way to implement in a convenient initializer using an instance of the class created in the implementation of the initializer?
source
share