-->

-fno-objc-arc not working to disable ARC

2020-08-17 17:54发布

问题:

I have tried the solution found in this post to disable ARC in AFNetworking files, but to no avail:

Any ideas where I am failing? Obviously the simpler the answer the better. I have also read that creating static libraries may help, but this seems complicated.

EDITS

I have tried deleting derived data and Clean and Build and restarting Xcode. No deals :(.

Also, there are no other projects in my workspace.

回答1:

Weird thing. I tried adding the -fno-objc-arc flag to some Facebook files and the project finally built. I guess the lesson here is that when Xcode generates these types of errors, the source of the problem may be in another file. This may especially be true if Xcode is complaining about a file that you have already flagged!

Hopefully this will be of help to somebody :).



回答2:

Just a little additional hint:

If you have multiple targets in your project check if you added the compiler flag -fno-objc-arc to all of them.



回答3:

"Convert to Objective-C ARC" is a code rewriting tool, -fno-objc-arc on the other hand is a compile time flag. It's simply irrelevant for the purpose of refactoring.

Before you click "Check", expend the target and deselect the files you want to keep ARC-free.



回答4:

Actually the problem is simple. Make sure there is no carriage return after the -fno-objc-arc flag you have entered in the compiler flags dialog.



回答5:

I managed to get into this state by a .m file that #imported a .m file that was not ARC compliant. The compiler complains about the included file, which may well be tagged -fno-objc-arc. I had to flag the .m that was doing the including.

I discovered this by expanding the build output on the failing and looking at the raw log which showed the file that was failing to compile (different from the one in the warning).

I also needed to delete the derived data file.



回答6:

Had the same issue but was unable to find the offending file (as in Brotto's solution). So simply wrapped the non-arc complaint code snippets in the following #if statement block:

#if !(__has_feature(objc_arc))

//...non-arc code

#endif


回答7:

I was able to fix my issues by unchecking the non-ARC files in the Refactor -> Convert to Objective-C ARC modal. Even though the files were already being disincluded due to the 'fno-objc-arc' flag. Once I unchecked the files, Xcode started spitting out better errors that allowed me to find files that needed some fixing. After making those changes, I was good to go.