In Xcode 6.1 and with the blog post about Failable Initializers on the Swift Blog, Apple has assigned to self in a failable initializer.
The Int (init(fromString:)) example on the blog post compiles fine when copied into my project with an assignment to self, but trying this with a custom class in my own code results in the usual error "Cannot assign to 'self' in a method".
extension Contact {
public convenience init?(context: NSManagedObjectContext = DataStore.managedObjectContext) {
if let userId = User.loggedInUserId(context) {
let contact = NSEntityDescription.insertNewObjectForEntityForName("Contact", inManagedObjectContext: context) as Contact
self = contact
} else {
return nil
}
}
}
(Contact is a subclass of NSManagedObject)
Is there anything I am missing with failable initializers?