I don't think the question mark in public init?(coder aDecoder: NSCoder)
means optionals. Also, when I override it I find I don't need to write the question mark at all.
So what does it mean exactly ?
--- Update --
The comment below had helped me figure that out, it is called "failable initializer", another example to make the concept easier to understand is UIFont's connivence init because that UIFont may not exist.
public /*not inherited*/ init?(name fontName: String, size fontSize: CGFloat)
init(coder:)Returns an object initialized from data in a given unarchiver.
@Raining The syntax is standard Swift function header syntax. "coder" is the name of the parameter that any code that calls this function will be required to use. If you don't want the caller to have to name the param, you write "_" instead of "coder".
It's called failable initializer. In the book, The Swift Programming Language, it describes it as
“It is sometimes useful to define a class, structure, or enumeration for which initialization can fail. This failure might be triggered by invalid initialization parameter values, the absence of a required external resource, or some other condition that prevents initialization from succeeding.”
Check the "Failable Initializers" section in the Swift Docs
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