Actually i came to this question when i was trying to add some classes that have been made upon ios prior to IOS 5 and these classes doesn't having ARC and the project i am trying to add is made upon the IOS 5 and it give me the compile time error related to ARC the classes having suck kind of information that if i try to remove the release/retain then it start behaving irregular.That is my problem, Now come to question i want to know that is there any way so that i can mark those classes not to use ARC so that the newly created classes that having base SDK ios5 compile with ARC and i mention not to use ARC simply compiled with their retain/release values.That is the only way i have left i think for making properly this app.
Any idea how i can use those classes that is having base sdk prior to ios5.
Thanks,
the image below will show you how to do it.
-fno-objc-arc flag to disbale arc
-fobjc-arc flag to enable arc
Go to your project settings, under Build Phases > Compile Sources
Select the files you want ARC disabled and add -fno-objc-arc compiler flags. You can set flags for multiple files in one shot by selecting the files then hit Enter key.
Go to Issue Navigator -> Validate project settings -> Perform changes. In this way Xcode automatically remove release and retain keywords from whole project and convert into ARC compatible.
Related
I want to know if my Xcode iPhone project is using ARC, and I can't remember if I ticked that box when creating the project.
How can I get this information?
Select your project, then Build Settings. Look for Objective-C Automatic Reference Counting in the Apple LLVM Compiler - Language section. Make sure you select the target; while you can set this in the project, the target can override it.
(You can also use the search bar in Build Settings for OBJC_ARC.)
Keep in mind, too, that you can turn ARC on or off on a per file basis in build phases.
Or, just try something like this in code:
[[[NSObject alloc] init] autorelease]
If you get an error:
ARC forbids explicit message send of 'autorelease'
Then you're using ARC.
You can also require ARC from a source code file by checking for it:
#if !__has_feature(objc_arc)
#error This file must be built with ARC.
// You can turn on ARC for only this file by adding -fobjc-arc to the build phase.
#endif
Just search for Automatic in your target's build settings:
Now I have a Xcode project which is built for iOS 5, but now i have to install it on an iPhone 3GS, which has a older iOS. I came to know that this is because I am using ARC in this project and it is not available in iOS 3.2. How can I remove ARC from my current project?
If you want it disabled for the whole project, you need to go to the target's build settings and set it to No
very simple first go to targets in that go "buldphases"-->compileSource--> here "yourfile.m" --> set value
-fno-objc-arc(only particular files )
if u want remove ARC in entire project go to targets in that go "buldsettings" ---> objective-c automaticrefcount :NO
In XCode, there is a global compiler flag called -fobjc-arc. If you disable this (-fno-objc-arc), ARC will be disabled in your whole project. If only a few files don't support ARC, use the -fno-objc-arc flag on those files only. The last flag "wins", see http://clang.llvm.org/docs/AutomaticReferenceCounting.html#general.
However, make sure that you know what you're doing! If the project was designed around ARC, there may not be any deallocation-code in there, including dealloc methods. Also, your properties might be unsupported (strong, weak etc.). You'll most likely end up in a complete mess.
Your best bet would be to just upgrade your 3GS.
Go
Build Settings
make sure "all" option is selected
search for automatic you will find Objective-c Automatic Reference counting set NO
I created a project without ARC. I want to use a third party SDK in my project. That SDK comes with ARC Support. So I want to add ARC for that third party files. I can disable ARC for all "MYProject" files by adding this flag into build phases like -fno-objc-arc.
But I may use large number of files. So it's better to add ARC for specific SDK only. So how to add ARC support for single or specific SDK files in XCode Project?
For Instance: I want to use Grid View. I'm adding GMGridView in my project and it comes with ARC support.
Add the flag -fobjc-arc to the files that you'd like to use ARC. It's just the opposite of the other.
You add compiler flags in Targets -> Build Phases -> Compile Sources
Compile source show all file that project contain.so please add -fobjc-arc to compiler flag by double clicking on it as show in below image.
I want to convert my app to ARC but I have some external librarys and frameworks that are not complaint with ARC. I know when yous start a new project using ARC, you can later specify which files to ignore. But can you do this when upgrading an existing app to ARC?
in XCode, go to your active target and select the Build Phases tab. In the Compiler Flags column, set -fno-objc-arc for each of the files you don't want ARC
EDIT:
Also, to have the opposite behavior, I mean to use a file that was written using ARC inside a non ARC project, you can set the file flag to -fobjc-arc instead
There is plenty of more info regarding ARC here: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#general
ARC may be explicitly enabled with the compiler flag -fobjc-arc. It may also be explicitly disabled with the compiler flag -fno-objc-arc. The last of these two flags appearing on the compile line "wins".
Source: http://clang.llvm.org/docs/AutomaticReferenceCounting.html
To add to Felipe's answer, if you want to add this to multiple files at once:
Select all the files you want to exclude form ARC
Press 'Enter'
The pop-up box will appear at the last file in the list
Type -fno-objc-arc
I'm trying to add a new target to my Xcode project so that I can run the same app, but with subtle difference.
Please can someone guide me through the setup of a new target since it is my first time and I'm not sure how to go about doing it.
In particular, I'm interested how I make the new target run the code in the original app. When I tried creating a new target it just made a new app delegate, and viewController file.
Sorry if this is simple, I'm just quite confused.
EDIT:
Please note that I'm after after instructions based in Xcode 4.
In xcode 4, make sure you're in the folder view where you have the project. Select the blue project button, then next to that you can see Targets, Select the target you have there, right click & select duplicate target.
Now you have two build targets.
To apply subtle differences in your app, make a global C flag. in Build settings there is a paragraph named GCC 4.2 - Language, it has a property named Other C Flags. Add your flag here like so:
-DOTHER_VER
Now in your code you can check for this using:
#ifdef OTHER_VER
// some code.
#else
// the subtle difference.
#endif
After you create your new target from settings of your project, you can create an identifier class to check the target. If you use macros everywhere in your code, it'll not be readable and feasible. You can check this tutorial-blog to learn how to do it, besides you may see some best practices there.