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

2018-12-31 00:18发布

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条回答
几人难应
2楼-- · 2018-12-31 00:25

Just use the -fno-objc-arc flag in Build Phases>Compile Sources

查看更多
查无此人
3楼-- · 2018-12-31 00:25

It is possible to disable ARC (Automatic Reference Counting) for particular file in Xcode.

Select Target -> Build Phases -> Compile Sources -> Select File (double click) -> Add "-fno-objc-arc" to pop-up window.

I had encountered this situation in using "Reachibility" files.

This is shown in below figure :

enter image description here

查看更多
孤独总比滥情好
4楼-- · 2018-12-31 00:26

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

查看更多
倾城一夜雪
5楼-- · 2018-12-31 00:27

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.

查看更多
倾城一夜雪
6楼-- · 2018-12-31 00:27

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

enter image description here

查看更多
谁念西风独自凉
7楼-- · 2018-12-31 00:30

If you're using Unity, you don't need to change this in Xcode, you can apply a compile flag in the metadata for the specific file(s), right inside Unity. Just select them in the Project panel, and apply from the Inspector panel. This is essential if you plan on using Cloud Build.enter image description here

查看更多
登录 后发表回答