Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a project without ARC into project with ARC

In X code, If I create a new project with automatic reference counting (ARC), and add an existing non-ARC project via File-->Add Files to (is that considered adding to workspace? Not sure about the workspace term), would that work? So the new code I write in this project can be ARC code?

When you add project this way, files are not listed in the "compiled sources"; therefore, I have nothing to set "-fno-objc-arc" on.

I notice that MapBox-ios-example seems to be doing this. Do you just add it in and not think about it?

A separate question is what if it's a non-ARC static library (.a) I'm linking to my ARC project? Do I have to do anything special with the classes in the non-ARC library?

EDIT: Hi sorry for the late response.

Almost all of you answered pretty well to my second question which I'm thank you all for it. Since nverinaud is the first to answer that question, I'm learning toward giving him the credit. (There seems to be a a time limit to awarding the bounty? If left the answers they are I would like to give nverinaud the credit.)

However I still have doubt to my first question. I'm adding a non-ARC "project file" itself into my current ARC project, according to the Mapbox examples and instructions). I must emphasize that I am NOT adding the source files (.m .c) into the project individually but adding the project file. The .m and .c seems to be in a separate project in a separate folder. And this Mapbox project has calls like [view release] and I don't NEED that special -fno-objc-arc flag to silence the warnings because the warnings aren't there.

I understand that usually when you add a non-ARC source files into your ARC project you WILL receive compiler warning which won't let you pass the compiler stages. However in my case I don't get any. My question in particular is not how to put the flag (which I know), it is whether or not I need the flag (I'm guessing I don't, I might even have compiler warning when I put it in? I didn't try.) Because, there is no warning whatsoever without the flag. And I am asking for some sort of explanation why there was no warning, and whether I am doing things right.

Here is a screen shot.enter image description here. OfflineSpotty is the ARC file I created. MapView.xcodeproj is the non-ARC project I added in. Hopefully the image clarifies things a bit.

like image 217
huggie Avatar asked May 23 '12 09:05

huggie


2 Answers

If you are including an non-ARC into a project that uses ARC, you will need to set the -fno-objc-arc compiler flag on all of the non-arc-source files.

To do this in Xcode, go to your active target and select the "Build Phases" tab. Now select each non-ARC source files, press Enter, insert -fno-objc-arc and then "Done" to disable ARC for these files. (unfortunately you have to add this line for each file and there isn't such a thing as group editing! :-( ) . Update: For Group editing, just mark the desired files and press enter! (no double click! Enter!) That's the trick! :-)

See Screenshot: a mixture of ARC and non-ARC enabled files

like image 200
Flori Avatar answered Nov 09 '22 21:11

Flori


If you are adding a compiled library to your project then you do not need to worry about anything, it won't matter if it is ARC or not because it is already compiled and hence the compiler doesn't have to compile it. Drag the static library into your project and make sure that you select your target under the Add to Targets section of the popup.

If you are adding project files to your project, then drag the folder containing the files into your app. A popup will show up, and under "Add to targets" make sure your app's target is selected. If you did this correctly, the non-arc files will show up in the compile sources section of your target's build phases. As other have stated, you can then add the -fno-objc-arc compiler flag to the non-arc files. To do this, select all of the non-arc files at once and press Enter. A popup will show and you can enter -fno-objc-arc in it and then press Done.

like image 1
Michael Frederick Avatar answered Nov 09 '22 21:11

Michael Frederick