Reputation: 63
I’m trying to return nil in my failable initializer but keep getting the error “All stored properties of a class instance must be initialized before returning nil from an initializer". Why?? Isn’t the whole point of failable initializers being able to return nil and stop initialization?
Upvotes: 3
Views: 352
Reputation: 442
Apparently it’s a bug that’ll be fixed as of Swift 2.2 https://stackoverflow.com/a/26497229/5792198
In the meantime, you can initialize all the properties with dummy data and set a flag. At the end of all the init code check the flag and return nil.
Upvotes: 3