Why doesn't Xcode make outlets unowned instead of weak?

Viewed 1017

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
5 Answers

It used to be that optionals could not be unowned. That's possible now, so unowned is appropriate. This is probably not done automatically because it would confuse somebody.

@IBOutlet private unowned var uiObject: UIObject!
Related