Why specify [unowned self] in blocks where you depend on self being there?

后端 未结 5 1586
后悔当初
后悔当初 2021-01-19 01:37

I want self to be non-nil and I\'m sure it will be, during the blocks execution. So why explicitly specify [unowned self] ?

object.executeBlock {
    date =         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 02:34

    The only time where you really want to use [unowned self] or [weak self] is when you would create a strong reference cycle. A strong reference cycle is when there is a loop of ownership where objects end up owning each other (maybe through a third party) and therefore they will never be deallocated because they are both ensuring that each other stick around.

    Do you have a strong reference cycle there?

提交回复
热议问题