I had created the sample application for testing the failable initializers. When I extends the NSObject then I am getting the below error.
1) Property 'self.userName' not initialized at super.init call.
2) Immutable value 'self.userDetails' may only be initialized once.
3) Immutable value 'self.userName' may only be initialized once.
Please find the below code and screenshot for the same.
class User: NSObject {
let userName: String!
let userDetails: [String]?
init?(dictionary: NSDictionary) {
super.init()
if let value = dictionary["user_name"] as? String {
self.userName = value
}
else {
return nil
}
self.userDetails = dictionary["user_Details"] as? Array
}
}
Screenshot