Want to perform action when __weak ivar is niled

前端 未结 3 1753

I have a @class Foo which contains a __weak id bar ivar. Several actions from methods in different classes can cause the object to disappear and th

3条回答
  •  被撕碎了的回忆
    2021-01-18 02:49

    I suggest to override dealloc. If you know the type of the object that will be allocated, and it's a custom class (otherwise subclass it), you can perform the action when the object is deallocated, which is exactly what happens when ARC sets the retain count to zero and sets the weak variable to nil.

提交回复
热议问题