Xcode produces outlets as weak vars with implicit unwrapping, like this:
@IBOutlet weak var nameTextField: UITextField!
I wonder why it didn't just make onowned var, which - in my understanding -
behaves exactly the same, but keeps the type non-optional. Is there any difference between these two?
weak var foo: UITextField!
unowned var foo: UITextField
A weak variable has a default value, namely nil, so your code is legal because the outlet property has a value at object creation time (before the outlet is actually connected).
But an unowned variable would have no default value and your code wouldn't compile. Try it.
Also the entire concept would be wrong. unowned is for a thing with a guaranteed independent existence and which you can't live without. A subview of a view controller's view satisfies neither of those.
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