gpt4 book ai didi

ios - 我可以将 retain 与 ARC 一起使用吗?

转载 作者:行者123 更新时间:2023-11-28 19:03:27 24 4
gpt4 key购买 nike

我正在阅读这份官方指南:https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447-SW13我不确定它是否指的是处理引用计数的旧方法,或者只是为了演示它是如何工作的——但是应该像使用访问器的例子那样手动使用保留/释放吗?

最佳答案

您不能将 retain 与 ARC 一起使用。但是,它在没有 ARC 的情况下仍然在后台工作(并且如您链接的文档中所述),但是编译器会根据需要添加 retainrelease 调用.你不必处理那个。

这个二传手:

- (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com