Objective-C:ARC禁止显式发送“保留"消息 [英] Objective-C: ARC forbids explicit message send of 'retain'
问题描述
我是Objective-C的新手,我尝试将用Objective-C的较旧版本编写的旧Objective-C项目移植到新项目,但出现以下编译器错误:
I'm new to Objective-C, I try to port an old Objective-C project written in an older version of Objective-C to the new one, but I'm getting the following compiler error:
ARC forbids explicit message send of 'retain'
in
color = [aColor retain];
or
color = [[NSColor blackColor] retain];
我正在阅读有关clang现在正在使用的新自动引用计数的信息.
我也尝试过使用Xcode的重构功能,但是没有运气...
需要替换此旧代码的正确的Objective-C代码是什么?
I was reading about the new automatic reference counting that clang is using now.
I have also tried to use Xcode's refactor function but with no luck...
What is the proper Objective-C code that need to replace this old code?
推荐答案
简单地:
color = [NSColor blackColor];
ARC将管理对象的生存期,因此您不再需要release
,retain
或autorelease
.
ARC will manage the lifetime of your objects so you don't need release
, retain
or autorelease
any longer.
这篇关于Objective-C:ARC禁止显式发送“保留"消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!