我正在阅读这份官方指南:https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447-SW13我不确定它是否指的是处理引用计数的旧方法,或者只是为了演示它是如何工作的——但是应该像使用访问器的例子那样手动使用保留/释放吗?
最佳答案
您不能将 retain
与 ARC 一起使用。但是,它在没有 ARC 的情况下仍然在后台工作(并且如您链接的文档中所述),但是编译器会根据需要添加 retain
和 release
调用.你不必处理那个。
这个二传手:
- (void)setCount:(NSNumber *)newCount {
[newCount retain];
[_count release];
// Make the new assignment.
_count = newCount;
}
在使用 ARC 时应该是这样的:
- (void)setCount:(NSNumber *)newCount {
// Make the new assignment.
_count = newCount;
}
关于ios - 我可以将 retain 与 ARC 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22731533/