Mixpanel iOS SDK and ARC - ios

I'm trying to add the Mixpanel SDK to an iOS app that uses ARC. After adding the SDK I get some compile errors related to ARC usage. How can I integrate Mixpanel into a project that uses ARC?
In my personal projects I always manage mempory manually. Perhaps there's some way to tell the compiler this code uses ARC while this code doesn't.

Click on your project name in the navigator. Choose "Build Phases" from the list header in the right hand window. You should see a bar named "Compile Sources"; expand it and you should see a list of the source files in the project and a column labeled "Compiler Flags". For every file in the Mixpanel SDK, double-click in this column and add the following line:
-fno-objc-arc
This will signal the compiler to not use Automatic Reference Counting when compiling these files. If you ever need to do the reverse (compile ARC code in a non-ARC project) do the same thing but add this line instead:
-fobj-arc
I believe this may be a duplicate of this question.

Related

Don't we need to link framework to XCode project anymore?

Base on this question
Why don't iOS framework dependencies need to be explicitly linked to a static library
I read the selected answer and still don't understand so I made an example project
Test Project on Github
In the test project, I remove all framework from Link Binary With Libraries and File navigation for both main project and the static library (including Foundation.framework and UIKit.framework too), basically, both project link to 0 frameworks.
Questions are
In static library, it's including MapKit/MapKit.h without referencing the Mapkit.framework to the project, why is its still working?
In main project, I remove UIKit.framework and Foundation.framework from the project, why is it still working?
Since it's working for now, will there be any issue later?
Thank you for your comment.
P.S. By working, I mean I can run on the simulator and I can archive the main project without any error.
Edit 25/07/2014
I tried with the real app that I'm working on, it's the same.
I highlight Foundation, UIKit, CoreData and 10 another frameworks in File Navigation, well, all of them.
Uncheck the target in Utilities Panel --> Target Membership
Build : Pass, Run : Pass
Every functionality of my app is still working as expected. I don't get this.
Check your project build settings. Underneath LLVM 5.1 — Language — Modules you should see the option 'Link Frameworks Automatically'. In your case it sounds like it's set to 'YES', the default.
In that case, instead of producing an error when you reference a class that the compiler doesn't know, it'll figure out which Framework contains that class and link it. In your code it'll be MKMapView or one of the other MapKit classes that triggers the linkage.
EDIT: from the relevant 'What's New?' document:
Auto Linking is enabled for frameworks imported by code modules. When
a source file includes a header from a framework that supports
modules, the compiler generates extra information in the object file
to automatically link in that framework. The result is that, in most
cases, you will not need to specify a separate list of the frameworks
to link with your target when you use a framework API that supports
modules.
Another way of looking at it is that the compiler is smart enough to mutate #import to #import when the framework has been built appropriately. All system frameworks have been.
To elaborate #Tommy's answer, a framework that supports modules satisfies the following 2 conditions:
Under Build Settings > Packaging
Define Modules is set to YES
Module Map File exists.
So, if you're certain that the framework you're using in your code modularizes like that, you can choose to not explicitly add it in the link phase as it will be automatically added as long as in the project file, under Apple Clang - Language - Modules, The option Link Frameworks Automatically is set to YES.

Errors when adding C libraries to a project with ARC

I am trying to use a set of C libraries to allow custom graphs in my iOS project. My projects uses ARC, however, the custom graph libraries are based on a project that does not use ARC. The errors I am getting are related to ARC.
The documentation for the C libraries specify that when using the library to turn off ARC. However, my project is too evolved to revert to a non ARC project.
How might I still use this library in my project? The library is PowerPlot.
You can turn off ARC for the specific library, by adding the -fno-objc-arc compiler flag.
Go in your Target Settings > Build Phases > Compile Sources, and add the compiler flag to every implementation file from the library.
Further information can be found here: How can I disable ARC for a single file in a project?

WhiteRaccoon iOS 4.2 errors

I have a app with the WhiteRaccoon framework installed.
I cant compile it as it gives me errors with anything to do with retain or release in WhiteRaccoon.m/h.
Any ideas whats going on?
Thanks.
By the way, I have added the CFNetwork framework. Any ideas?
Your project is probably using ARC and WhiteRaccoon probably isn't.
You can either convert whiteRaccoon (whatever that is) to ARC or exclude the whiteRaccoon files by adding the following compiler flags to it's source files -fno-objc-arc.
To do that click the project on the left hand side then go to the "Build Phases"-> "Compile Sources" look for the white Raccoon .m files and add the -fno-objc-arc under the compiler flags section.
Another option would be to compile the WhiteRaccoon framework into a static library and as this to your project.

Apple's Reachability without ARC

I want to check Internet connection in my app. So i use Apple's Reachability sample code.
But because of using ARC there are some errors. I correct some of them but other errors still in my code.
How should i solve this problems? Any ideas?
Thnx.
You can disable ARC on a per-file basis.
Select the project in the file list
Select the target
Click the Build Phases tab
Open the Compile Sources phase
Scroll down until you find your source file (or use the search field)
Double-click in the Compiler Flags column for that file
Enter -fno-objc-arc
Now ARC is disabled for that one file.
Try using this for your ARC version code -> Reachability (iOS) ARCified

How to remove ARC from XCode

I have already created a project in XCode 4.2 with ARC checked. The problem is that I have to download and add the ASIHttpRequest files. This is giving a whole bunch of errors when I try to compile. Is there some way to fix this (other than to create a project again) ?
Click on the name of the project on the navigation view in the left side, go to Targets -> Build Phases and add -fno-objc-arc to the "compiler flags" for any relevant files.
You can turn off ARC per-file by passing the flag -fno-objc-arc to each as they are compiled. Add the flag to the files that need ARC disabled in the Compile Sources group under the target in the project navigator.
Another option would be to compile ASIHttpRequest as its own framework that doesn't have ARC enabled and just link against the framework. Speak of, isn't ASIHttpRequest already in a framework? (I've not looked at it in a while)
Keep using ARC, but disable it for the ASIHttpRequest files. This answer should point you in the right direction:
How can I disable ARC for a single file in a project?

Resources