Daily iOS
Memory and ARC

Choosing weak vs unowned

When would you use unowned instead of weak?

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

Use unowned (no optional, no nil handling) when the target is guaranteed to outlive you or die with you, and weak when you aren't sure. A child referencing back to its parent, or a closure in a view referencing the view controller that owns it, are legitimate cases.

Share a question