Daily iOS
Memory and ARC

unowned access risk

A coworker wants to declare every delegate unowned instead of weak because unwrapping optionals is a hassle. Why isn't an unowned reference optional?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

unowned is a reference built on the promise that the target won't go away before you, so the runtime doesn't set it to nil when the target is deallocated; that's why it doesn't need to be optional, and if the promise breaks and you touch the deallocated target, you get an immediate trap instead of a nil check.

Share a question