How can I disable ARC for a single file in a proje

2019-08-06 21:23发布

I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing that there was a way to disable ARC on a per-file basis, though I have been unable to find this option.

Is this possible? How do I disable ARC on a per-file basis?

18条回答
Melony?
2楼-- · 2019-08-06 21:57

It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.

You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box. (Note that editing multiple files will overwrite any flags that it may already have.)

I created a sample project that has an example: https://github.com/jaminguy/NoArc

xcode

See this answer for more info: Disable Automatic Reference Counting for Some Files

查看更多
该账号已被封号
3楼-- · 2019-08-06 21:57

For Xcode 4.3 the easier way might be: Edit/Refactor/Convert to objective-C ARC, then check off the files you don't want to be converted. I find this way the same as using the compiler flag above.

查看更多
Deceive 欺骗
4楼-- · 2019-08-06 21:59

I think all the other answers are explaining how to disable MRC(Manual Reference Count) and enabling ARC(Automatic Reference Count). To Use MRC(Manual Reference Count) i.e. Disabling ARC(Automatic Reference Count) on MULTIPLE files:

  1. Select desired files at Target/Build Phases/Compile Sources in Xcode
  2. PRESS ENTER
  3. Type -fobjc-arc
  4. Press Enter or Done
查看更多
Lonely孤独者°
5楼-- · 2019-08-06 21:59

Following Step to to enable disable ARC

Select Xcode project Go to targets Select the Build phases section Inside the build phases section select the compile sources. Select the file which you do not want to disable ARC and add -fno-objc-arc

查看更多
成全新的幸福
6楼-- · 2019-08-06 22:05

use -fno-objc-arc for each file in build phases

查看更多
冷血范
7楼-- · 2019-08-06 22:05

Please Just follow the screenshot and enter -fno-objc-arc .

enter image description here

查看更多
登录 后发表回答