Weak & unowned self inside operators

While going through the book, a question popped up:

When I declare a self property inside a closure of a function in a UIViewController class, I make it unowned. The rationale is that for the lifetime of the VC, self cannot be nil.

I see that in the book, you declare it mostly as a weak variable (for example in Chapter 6 and in other places). Is my rationale wrong while declaring self as unowned instead of weak, or is there a specific reason you do it that way?

In case the view controller is dismissed and your asynchronous task completes after that you will have a crash because self will be nil. The safe way is to use weak.

This topic was automatically closed after 166 days. New replies are no longer allowed.