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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With