Automatic Reference Counting Issue - PhoneGap - iphone

I have tried creating my HelloWorld Application using PhoneGap + Xcode 4.2 by following some steps as explained on below link:
http://docs.phonegap.com/en/2.5.0/guide_getting-started_ios_index.md.html#Getting%20Started%20with%20iOS
But when i'm running my HelloWorld application on Simulator..its giving my Automatic Reference Counting Issue error.

This error is coming cause your project CordvaLib is ARC enabled. However, your class CDVAccelerometer isn't ARC enabled. To exclude the file from ARC, use the -fno-objc-arc flag
in build phases > compile sources

While creating the new project it asks "use Automatic Reference Counting" with check mark. If you are not using ARC then deselect the check mark.
If you don't want ARC for the only particular class then ProjectSettings -> Build Phases -> Complile Sources -> Compilerflag. click next to your class and set
-fno-objc-arc
Now only the selected class is ARC disabled.

Related

having errors when import class non-Automatic Reference Counting to my project

Just create new project and checked Automatic Reference Counting and downloaded another project.
when I import the downloaded classes to my project, it gives too much errors, after searching I found that because the downloaded project is non-Automatic Reference Counting .
so, what is the solution for this problem please ?
This occurs because calls like "release" cause errors in ARC projects so that you don't use them because the compiler does this for you. To keep ARC enabled on your classes and disable it on the class you've imported go to your build phases and add the compiler flag "-fno-objc-arc" to the class that you want to use manual memory management.
Those files need to be flagged to the compiler so the compiler does not use ARC with them. Use the -fno-objc-arc flag. Click on your project file, click on your application's target, click on the "Build Phases" tab, expand on "Compile Sources", and double click on the files without ARC. Once a little window pops up, put the -fno-objc-arc flag on those files.

Adding reachability to iphone application gives linking errors

I keep getting these errors trying to run the Reachability.h
Go to Project build phases and add the following
Under Compile sources, press the "+" icon and add Reachability.m
Under Link Binary With Libraries press the "+" icon and add SystemConfiguration.framework
UPDATE:
If you are receiving ARC compilation errors
You will have to disable ARC on specific files
To do that please follow the steps in this answer
How can I disable ARC for a single file in a project?
Your class is referencing Reachability, but you are not adding it to your project. You should possibly add the Reachability.m file to the project.

Use Automatic Referencing Count in specific classes in ios

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.

How to add ARC for specific file?

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.

Files doesn't support the ARC feature, how to deal with

My project uses the ARC(Automatic Reference Counter), so when i try to import the ASIHTTPRequest library which has 4 classes that used in their implementation the autorelease statement, here is an example:
[self setAccessLock:[[[NSRecursiveLock alloc] init] autorelease]];
The error that i got:
ARC forbids explicit message send of autorelease
What should i do to solve this problem.
I have got the solution, i needed to add the right flags to the compiler flags for each file which doesn't support the ARC. For me, i use Xcode 4.2, so under target -> Build Phases -> Compile Sources, double click on the file you want to disable the ARC feature and put -fno-objc-arc the click on Done. And it's Done ;)
Please note, that if the file doesn't exist on the list, you can just add it by clicking the + button and then perform the same work above.
Disable ARC for that one class
When you migrate a project to use ARC, the -fobjc-arc compiler flag is set as the default for all Objective-C source files. You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class.
In Xcode, in the target Build Phases tab, open the Compile Sources group to reveal the source file list. Double-click the file for which you want to set the flag, enter -fno-objc-arc in the pop-up panel, then click Done.