Objective-C: ARC forbids explicit message send of 'retain'

天涯浪子 提交于 2019-11-29 09:50:39

Simply:

color = [NSColor blackColor];

ARC will manage the lifetime of your objects so you don't need release, retain or autorelease any longer.

The main advantage of ARC is the compiler will clear the references of all objects automatically that you have created in your projects. So There is no need of retain, release, & autorelease. But some cases we want to release our particular files from ARC. To release your project from ARC in xcode. Please follow the following steps.

1.Click your project for Build Phases.
2.Click the drop down menu named as "Compile Sources".
3.Double Click the file that you want to free from ARC.
4.Type the following to set the compiler flag.

       "-fno-objc-arc" 

This flag will release that particular file from ARC of your Compiler in xcode.

I hope this will help you for all of your projects.

Ege Akpinar

Just remove retain, so:

color = [NSColor blackColor]

With ARC, you cannot use retain, release, autorelease as it does them for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!