How to build an Objective-C static library? [closed]

For XCode 5. These answers seem a bit out of date.
You can see the main steps here http://www.raywenderlich.com/41377/creating-a-status-library-in-ios-tutorial . But Xcode 5 does a lot more work for you and now works nearly as you want it to.

1.Create new Static Library App in Xcode
New Static Library in Xcode

2.You can delete any files it creates and add your own. Add your methods etc.
Code Code Code

3.Little problem with Static Libraries, is that you can only build either for the device or run in the simulator. So we need to create a library that supports ARM and i386 Architectures, to do this we need to create a universal binary (so it will support simulator and on device builds).

Create a new target (File > New > Target).
New Target

4.Select New Target then add a new build phase (Editor > Add Build Phase > Add Run Script Build Phase
New Build Phase

5.Select the build phase and enter the script from this link into run script window.
https://gist.github.com/sponno/7228256

Run Script Code

6.Now you need to build each architecture (simulator and iOS device)

6.2.Select our libary and then iOS Device, click build or run (Command + B)

6.3.Then for the Simulator (select the Library Icon very top left of Xcode and then the iOS Simulator)
enter image description here

7.Now you want to build the BullsEye icon > iOS Device. This will be the aggregate target and will combine our two libraries into a new universal file.

8.Lets see if this all worked.
Expanded the folder “Products” in the left tree, right click on the file ending with “.a” and “Show in Finder”

9.If this all works you should see the following files in finder.
You will see the
Library .a file and include files

10.The last step is easy, simply drag the “library.a file and the includes folder into your new Xcode project.
enter image description here

enter image description here

In your new project, you wont have to do anything else, other than import the header files that want to use, but you do not have to change the linking flags, or header search paths. It will just work.

Bonus points

Install VVDocumenter https://github.com/onevcat/VVDocumenter-Xcode and use this to document any header.h files that you will share with the library.

Now anyone that is using your library can opt+click to bring up context aware help for you classes.

Context Aware Help based on header file

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)