Whats the Difference Between Unowned and Weak References?

TIL I finally learned when to use unowned as opposed to using weak. Under the hood: unowned is essentially a force-unwrap of a weak capture, with all that it entails. Because of this using it slightly more dangerous. Crash danger: Accessing an unowned reference while it’s nil will cause a crash. Compilation error: Every weak reference, must be an optional property. Otherwise you’ll get a compilation error: weak var delegate: DataEntryDelegate = DataHandler() // ERROR: 'weak' variable should have optional type 'DataEntryDelegate?...

March 11, 2022 Β· 3 min