Create static library in Xcode 4 - ios

I can't figure out how to create a cocoa touch static library in Xcode 4.
I've created static library in Xcode 3 and it worked fine. I used this tutorial. Thanks for the help.
First step I create cocoa touch static library
Next we can see our static library in product directory. But now this uncompiled library.
Next step I add some objective-c class. This class is will perform various actions, for example show NSLog messages.
Then I made sure there is this class exist in compile source
After that I build my target
Now I use this static library in other projects, but when I use it I get a error when linking files with my static library.

Open Xcode > Create New Project > iOS > Framework & Library > Cocoa Touch Static Library

I struggled with this myself and, on another SO thread, found this:
iOS-Universal-Framework

To create an static library you can try to figure out with example example here: http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial

Related

How to use cocoapods in xamarin.ios

I would like to make use of couple of cocoapods in my xamarin.ios project.
But I couldn't find those cocoapods in Nuget which is package manager for Xamarin.
I heard we can compile a xcode project into a static library ... that is .a file and use it in xamarin.
But I am getting confused on how to convert the pods into a static library or something so that I can use those pods in my xamarin.
You cannot take the Pod directly and create a static library but you can although create a static library from the Pod project which already contains your pod. But to be honest the best solution will be getting the source code of the project and create the static library from there. Most of the Pods out there are open source so grabbing the source code from github should not be a problem.
Once you have the source code follow this example to show you how to create static libraries from there.
Once you have created the static library you just need to follow this tutorial to create a Binding library that can be used in Xamarin.
Unfortunately AFAK there's not support yet for Swift libraries to create binding libraries so this will only work with objective-c code.

is there need of static library to create framework?

Is this necessary to create static library for creation of framework or we can create it without help of static library what is diffrence betwwen them.
You have two options for creating framework, one is static library (code is linked at compile time) and iOS8 onwards dynamic framework(code is linked at runtime). Refer to following answers for knowing the difference between them :
Library? Static? Dynamic? Or Framework? Project inside another project

Creating a Static Library in Xcode 5

Hi guys I'm having a bit of trouble creating a static library in xcode 5. Most of the tutorials out there are done in xcode 4 and thanks to apples incredibly easy to use gui, that makes it so easy for users to transition from one program to another, so I haven't been able to make one and use it.
So I get that the first step is to make the cocoa ios static library project and then to add the header and implementation files (.h and .m) that you want in your library.
Next you supposed to set the header files that you want to be accessible by the user. Is it possible to set up the library in such a way that importing one header file also imports all of the other header files? Do the other header files need to be public to do this?
My main problem is how do I actually set the classes which I want to be public/private and finally how do I implement this library into one of my applications?
A HelloWorldLibrary example would be great!
After using the link: github.com/jverkoey/iOS-Framework
I am now having a problem with the locating of the Framework:
ld: warning: directory not found for option '-L/Users/Harry/Library/Developer/Xcode/DerivedData/SampleFramework-efznryzmlxnimoaaazjfbqjirzxq/Build/Products/Debug-iphoneos'
ld: framework not found SampleSubproject
There are steps to create static library.
I have not created in xCode 5, but have created in 4.x..
Create new project and select Cocoa touch static library under iOS.
Add Class files/Resources to your created project.
Set Installation Build Products Location to $(BUILT_PRODUCTS_DIR)
Copy headers in Build Phases
Set headers to Public in Target Membership
Build for Archiving/Profiling
got it from derived data (Release iphonesimulator, Release-iphoneos)
now merge both .a files using
lipo command from terminal like lipo -create libForDevice.a
libForSimulator.a -output UniversalLib.a
Now copy this lib to your main xCode project and include your perticular class.
You can find more details from here
Regards.

Embed OpenCV framework inside another xCode project without linking

I have developed an xCode static library for an iPhone App using OpenCV.
Now I want to give my static library to them but I don't want them to go through the hassle of making OpenCV work in their project by changing build settings and all that, that's what I already had to do myself in the static library.
I usually use the 'Projectception' method by dragging my static-library-project into my main xCode project. However when I use this method I usually need to add all the frameworks I use in the static library project again in my main project in the 'Link Binary with Libraries' build phase.
So my question is: is there a way that the OpenCV is only in my static library project and that a new project that imports this static library does not have to do anything extra for OpenCV to work?
Yes. Clone(copy) opencv inside your project (headers and implementation)*, desclare the copied files inside your project and don't use any c/c++ include folder and any library linkage.
*implementations are in modules/.../src/

Creating static library which depends on other static library (RestKit)

I followed the following tutorial to create a static library:
https://github.com/jverkoey/iOS-Framework/#developing-the-framework-as-a-dependent-project
It all works until I try to incorporate the RestKit into my static library. There I am completely lost. Am I supposed to include the RestKit library into my static library or only in the App which will use my library?
If I don't include RestKit in my library, I can't compile it as it depends on another library (RestKit) so what would be workaround for this?
I tried to look everywhere but haven't found a good step by step tutorial to create a static library which itself depends on other static libraries.
What I did to get this working was to add RestKit to my static library using their git-submodule instructions here. Then I performed the exact same steps on the projects that were going to use my static library EXCEPT:
I did not add RestKit to the "Target Dependency" section of the Build Phases
I did not add the libRestKit.a to the "Link Binary With Libraries" section. All other references still needed to be added.
I was then able to reference RestKit in both my static library and my iOS project.
COCOAPODS MEGA HACK
I was able to get this working with cocoa pods, but it will only work if this is your only cocoapods project. I started with all of my projects in a single workspace. Then I had my single podfile install RestKit to my static library and all projects that were going to reference my static library. Then for each project that I wanted to reference my static library I removed the pod reference under "Linked Frameworks and Libraries". Everything was then working as expected.
As you can expect, this would probably break all other pod references (unless you managed them all through that one static library), but it does seem to work.
Shorty after asking the question I finally managed to get it working here the steps if someone has a similar problem:
Create an actual app as explained int this section. After adding your library add all the other libraries you use to the application. (In my case it was the RestKit framework, add it as a submodule and not with cocoapods as with cocoa pods it didn't manage to get it to work properly).
After adding all your libraries, follow the third party libraries instruction for modification for the application and make the same modification for your static library.
e.g. for Restkit I had to add
-ObjC -all_load
to the Other Linker Flags and add
"$(BUILT_PRODUCTS_DIR)/../../Headers"
to the Header Search Path inside my static library.
I still couldn't build as the <RestKit/Restkit.h> wasn't found, so I needed to change the build order of the frameworks to assure that Restkit was built before my library.
This is done inside the edit Scheme of the build menu. Make sure that all the dependent libraries are on top of your library (if your static library or the dependent libraries aren't already in there add them with the '+')
Afterward everything worked for me. I am not sure if this is the best method to do it or if it would be better to include the third party library inside your statistic library.
Update I still run into problems when trying to build my library, if someone has a better solution or can shed some light on how to create a static framework which depends on other frameworks I would appreciate it.

Resources