Pergunta

I've tried to convert my non-ARC project with release and etc. to Objective-C ARC via Edit->Refactor in Xcode but during conversion I get errors in SBJson parser source files: "This source file must be compiled with ARC enabled!". But I use SBJson 3.1 which is ARC version.

So I don't understand what is wrong. Can someone help with this?

P.S. I tried to follow advice in the answers but result is the same:

enter image description here

enter image description here

As you see adding this flags didn't help.

Foi útil?

Solução

The error message comes from SBJson.

NSObject+SBJson.m:

#if !__has_feature(objc_arc)
#error "This source file must be compiled with ARC enabled!"
#endif

As a guess, the refactor task tries to compile the project without ARC in order to inspect all the objects inside.

I'm not sure about this refactoring tool, there may be a way to exclude some files from the refactoring. If that fails, then I would try commenting these lines out on any SBJson file until the refactor completes, then after the project has be refactored you can restore the SBJson files.

Outras dicas

Go to your project settings and click on "Build Phases". Open up "Compile Sources", highlight all the SBJson files and double click one. Type in -fobjc-arc.

Another way to do it, and recommended in the SBJson documentation:

http://deshartman.wordpress.com/2011/09/02/configuring-sbjson-framework-for-xcode-4-2/

Basically, you include the sbjson framework as a project inside your project, then link your binary to the framework. The framework is then compiled separately, thus no ARC conflict.

Note that it is important how you drag the SBJson.xcodeproj into your project - make sure that it is in the file tree of your project, not created as a separate project that makes a workspace. The link above shows a screenshot of how it should look. Note that after I dragged the SBJson.xcodeproj into my project, I had to restart Xcode to get it to show up right.

Another way is to use workspaces. You would create a workspace that has both projects, then link the sbjson framework in a similar way. When I did this, there was no need to add anything to "target dependencies" as shown in the link above, but I did need to add the project in "link binary with libraries". Here's how this setup looked on my machine, where "SBJSONTestWorkspaces" is the name of my project where I want to use SBJson:

enter image description here

Here's some documentation on workspaces:

http://developer.apple.com/library/mac/#featuredarticles/XcodeConcepts/Concept-Workspace.html#//apple_ref/doc/uid/TP40009328-CH7

As your project is created in ARC so xcode expects every file to be ARC compatible. While SBJSON files must not be according to the ARC standards. You need to exclude these files from ARC check. This can be done via selecting files that need not to be checked for ARC. This can be done if you go to your project settings -> Build phases -> complie sources. There would be your files of SBJSON you can add different flags here. To Ignore the ARC check you must add '-fobjc-arc' flag. You can do so via double clicking a file, a new windows pop ups and add the above flag in that window.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top