0

在支持 iOS 4.3 之前,我使用过 ARC 并构建了应用程序,但是当我开始使用weak时,因为 Tree 对节点有强引用,而节点对树有一个引用,这应该是一个弱引用:

@property (weak, nonatomic) NSTree *treeThatIBelong;

NSTree是我在自己的代码中创建的一个类)。

在这种情况下,无法使用 iOS 4.3 的目标,因为编译器错误是“weak... is not supported in the deployment target”,只有在 iOS 5.0 或更高版本时错误才会消失。所以如果我们有一个weak,我们不能部署到 iOS 4.3 吗?如果我们想要支持 iOS 4.3 并且仍然使用 ARC,是否有解决方法?

4

1 回答 1

1

The workaround is to not use weak if you need to deploy to iOS 4.3 or earlier. weak requires runtime support that's not present until iOS 5.0.

For iOS 4.3 and earlier you can use assign, which of course is not a zeroing weak reference and therefore just turns into garbage when the referenced object is deallocated. Which is exactly what you have to deal with already when using MRR instead of ARC.

于 2012-09-06T07:26:57.673 回答