本文介绍了想要在__weak ivar被破坏时执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个@class Foo,其中包含一个__weak id bar ivar.来自不同类的方法的几种操作可能导致对象消失,从而被bar破坏.

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 thus get bar niled.

当ARC自动禁用ivar时,我想执行一个操作.

I want to perform an action when the ivar is automatically niled by ARC.

如果可能,我要避免将bar转换为属性或使用键值观察.

If possible, I would want to avoid turning bar into a property or using Key-Value Observing.

这甚至有可能吗?如果不是,可以将KVO用作非财产的垃圾吗?

Is this even possible? If not, can KVO be used against non-property ivars?

推荐答案

KVO无法成功用于非财产IVAR.

KVO cannot be successfully used on non-property IVARs.

当Objective-C的ARC使IVAR无效时,您将无法从运行时进行检测.

You cannot detect from the runtime when Objective-C's ARC nils an IVAR.

这篇关于想要在__weak ivar被破坏时执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:13