import non-ARC code compiled .a file in ARC enabled project - ios

There is a SVGKit on github is compiled in non-arc code, and I get its library file, named SVGKit.a and some header files.
However, my app project is developed on iOS 7 and above, so by default it is managed by ARC.
My question is, is it safe to link the non-ARC library .a file into my project and use it like usual? If not, then how can I use it?

is it safe
From an ARC point of view, certainly. ARC operates at compiler level - and your library is already compiled. One way or another, it is already doing whatever memory management it is doing.
Now, there may be other reason why you'd have trouble linking to a library; but that would have nothing to do with ARC.

Related

Make static library for iOS with existing C code in Xcode

Short version of the question:
So basically what I'm looking to do is to take an existing library written in C (https://github.com/lsalzman/enet) and turn it into a static library for iOS.
I am just looking for an easy to understand step by step of how to accomplish this in Xcode.
Long version:
I've gone over some tutorials for making a simple static library that's written in Objective-C (http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial), and I generally understand what is happening there, but I'm failing to understand how to do this with existing code written in C.
I think I'm getting close, but I'm not so sure.
I start out by making a "Cocoa Touch Static Library" project in xcode.
I add all of the enet .h and .c files
make sure the enet stuff is in my "User Header Search Paths" in build settings.
hit build - it compiles!
The generated .a file is 517kb, so I'm pretty sure it's building the enet stuff in at this point.
My problem right now though is that the header file for the library is basically empty:
#import <Foundation/Foundation.h>
#interface enet_ios : NSObject
#end
I'm thinking I either need to write a wrapper in Objective-C that talks to the enet library, or I need to reconfigure my xcode project somehow so that enet.h is the 'entry point' into this library and not xcode's pre-generated .h/.m files. I'm not really sure how to do that, though. Ideally I'd just like to skip any sort of wrapper and use what the enet library is already providing me.
Thanks for taking a look!
Question, are you trying to call the functions using objective c syntax / object orient notation? Then you do need a wrapper object, no way around that.
But if you are fine calling C functions directly, which is completely acceptable in IOS/Objective C, then it is a matter of making sure your header files from the enet library (the ones in the include directory I see in the github link you shared) are also distributed with the static library. This is a limitation of the static library. You can copy them with the *.a, but they must be copied with the static library. This does differ from a Framework, which has included .H and assets, which developers are not easily able to create with Apple's tools for IOS.
I find that library management with Objective C to be painful on its own and static libraries a challenge for this and many other reasons. One more suggestion, definitely more elegant and portable but slightly overkill for personal use, would be building the project as a cocoapod. You can do this by forking the project and converting it to cocopods. There are lots of examples of how the project structure should look on cocopods and other OSS like AFNetworking. This seems to be the defacto standard way people are creating IOS libraries. See http://cocoapods.org/ for more details. This will include the source code as the pod and compiled against the target application.
This is the only way i deal with my own libraries and third party libraries. It has gotten to the point that if the library doesn't use cocoapods, i don't use the library or fork it and do make it a pod myself....

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?

Shifting to ARC even if some third part library is on non-ARC implementation

I have started using ARC (Automatic Referencing Count) in my project. I am using couple of third party libraries (which I have received from another team) which are still on non-ARC code. Is it safe to start using ARC even if external libraries do not conform to ARC?
Absolutely, it is safe to use ARC alongside the compiled non-ARC code. The compiler is smart enough to insert the retains and releases where necessary.
If other libraries are given to you as source code, you can disable ARC just for these files by adding the -fno-objc-arc compiler flag, and it is going to work together with your ARC-enabled code. You can add this flag in the target's build phases.

How to build static lib without ARC for a project which uses ARC?

How can I build a static lib without ARC for a project which uses ARC?
I found some source for a static lib, I want build it for my project but I use ARC.
The static library can be built without ARC and included in your project with ARC without doing anything special. If you want to add the source directly, you'll need to add the following compilation option to each non-arc file in build phases: -fno-objc-arc.
In general case : You can opt for few files(static lib) not using ARC and your own files using ARC.
But for lib it is not required.
You can merge ARC and Non-ARC files quite simply, however you have compiled lib then it doesn't care.

Using an ARC static library in a NON-ARC project

I am trying to get this sorted out. I know how to get an ARC project working with files or static lib's that are not using ARC. For instance, using the compiler flags -fno-objc-arc.
But what if I have a project that is not using ARC and want to include a static library compiled with ARC? Every time I want to build the project it is telling me that it doesn't recognize things like "strong, __unsafe_unretained,...".
To add on to shw's answer. Add -fobjc-arc to compiler flags under build phases to ARC files to make them compile correctly for non-ARC projects.
More info here
It should work fine - are you sure you're using the newest Apple compiler with this non-ARC project and not the GCC one?

Resources