Recently, after developing a collection of applications for iPhone that were intended to be used as libraries, I began looking into how to convert Xcode projects into static libraries. Most of what I found was vague, unclear, and outdated. Instructions were either for older versions of Xcode, or assumed that you were creating a blank library, and would be coding after creating a new project.

So, I read through several tutorials, and believe that I have come up with the best way to convert a finished, working project into a library for use.

Creating a static library

First, you need to create a new Xcode project. From the template selection screen, choose Cocoa Touch Static Library under Framework & Library for iOS.

You can give the project whatever descriptive name you would like, and you can change the name of the resulting .a (archive) file to whatever you want in the end. Select where you want to create the project and press create.

Next, remove the .m and .h file that were auto-created with the project. They should be named the same as the newly created project.

Next, select the files from your original project that you want included in the library, and move them to the library project. Be sure to include the .m and .h file for each file wanted, as well as any .plist or other resources, such as libraries, that the files need or reference. When copying the files, be sure to select the check box under Add to Targets to ensure that all the imported .m files will be included in the library.

At this point, you should check that the prefix file of the library project has all of the necessary imports, to prevent build errors within your library.

Now, we want to build the library for both device and simulator, starting with the device. To build the library for a device, either select a connected device from the device list or select iOS device from the list, as below.

Then build the library. If the build was successful, the filename of the .a file in the Products folder should now be black.

To build the library for a simulator, select a valid simulator from the device list, and build the library again.

Next, we are going to locate our newly created libraries. You can right click the created library under Products and select show in finder to open the folder containing the device build.

The enclosing folder is the Products folder of the library project, and contains two folders, one for device, and one for simulator.

The next step is to combine these two libraries into one “fat” library that can be used for device and simulator. The easiest way to do this is to copy the two libraries to another folder, renaming them to distinguish them.

From the terminal, navigate to the folder containing the libraries and run the following command, substituting the names of your libraries:

lipo -create libPictureTouchLibraryDevice.a libPictureTouchLibrarySimulator.a -output libPictureTouchLibrary.a```

This will create a new library in the same folder that can be used for either devices or simulators.

Finally, to distribute the library, we need to include the .h files and any resources, such as plists, that will be used in the library. These files, along with the “fat” .a file are allyou need to implement the library.

<img src='/blog/349/files/CreateLibrary7.png' />

You now have a static library, ready to be added to any Xcode project.

#Adding a static library to a project#

First, if you created the library as mentioned above, and are adding the newly created library back to the project it originated from, be sure to remove any .h or .m files that are included in the library before adding it.

<img src='/blog/349/files/CreateLibrary8.png' />

Next, add the .a file and all resource files to the project. Be sure to select the check box under Add to targets to add it to the main target of the application.

<img src='/blog/349/files/CreateLibrary9.png' />

Otherwise, you will have to add the library under the build settings of the project. The library should now be working! You can now reference it anywhere within your project.

Creating and Using Static Libraries for iPhone using Xcode 4.3的更多相关文章

  1. Using Open Source Static Libraries in Xcode 4

    Using Open Source Static Libraries in Xcode 4 Xcode 4.0.1 allows us to more easily create and use th ...

  2. Building Objective-C static libraries with categories(ObjC、all_load、force_load)

    https://developer.apple.com/library/mac/qa/qa1490/_index.html    之所以使用该标志,和Objective-C的一个重要特性:类别(cat ...

  3. 「操作系统」:Linker Use static Libraries

    While static libraries are useful and essential tools, they are also a source of confusion to progra ...

  4. Openssl - Static libraries (w32, mingw) 以及对Qt静态编译时的设置

    Openssl static libraries created for Windows 32bit using MinGW compiler   Compiled with:       ./Con ...

  5. Building Objective-C static libraries with categories

    Q: How do I fix "selector not recognized" runtime exceptions when trying to use category m ...

  6. Build fat static library (device + simulator) using Xcode and SDK 4+

    155down votefavorite 185 It appears that we can - theoretically - build a single static library that ...

  7. Creating a simple static file server with Rewrite--reference

    Today, I’d like to take a quick moment to demonstrate how to make a simple file server using Rewrite ...

  8. iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址(2014年2月19日更新版)

    //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3496069.html     编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 ...

  9. iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译

    编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 1 苹果API常用英语名词---iOS-Apple苹果官方文档翻译 http://www.cnblogs.com/ChenYilong/p/ ...

随机推荐

  1. Kreyos 资料收集

    Kreyos 资料收集 使用 默认需要连接 APP 解锁. 固件 https://github.com/kreyosopensource/KreyosFirmware Android 源码 https ...

  2. Python学习之变量的作用域

    学习地址:http://www.jianshu.com/p/17a9d8584530 1.变量作用域LEGB 1.1变量的作用域 在Python程序中创建.改变.查找变量名时,都是在一个保存变量名的空 ...

  3. linux composer的使用

    安装好的composer使用很简单,分两步加载组件例1.搜索组件:composer search phpexcel2.下载组件:composer require 厂商名/包名然后在使用该插件的脚本中引 ...

  4. 网络监控之一:netstat命令

    netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况.netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP ...

  5. TCP与UDP比较 以及并发编程基础知识

    一.tcp比udp真正可靠地原因 1.为什么tcp比udp传输可靠地原因: 我们知道在传输数据的时候,数据是先存在操作系统的缓存中,然后发送给客户端,在客户端也是要经过客户端的操作系统的,因为这个过程 ...

  6. windows提权辅助工具koadic

    项目地址:https://github.com/zerosum0x0/koadic ┌─[root@sch01ar]─[/sch01ar] └──╼ #git clone https://github ...

  7. java成神之——集合框架之ArrayList,Lists,Sets

    集合 集合种类 ArrayList 声明 增删改查元素 遍历几种方式 空集合 子集合 不可变集合 LinkedList Lists 排序 类型转换 取交集 移动元素 删除交集元素 Sets 集合特点 ...

  8. Windows修改MySQL用户root密码

    MySQL是一个关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软 ...

  9. Java微信公众平台开发(九)--关键字回复以及客服接口实现(该公众号暂时无法提供服务解决方案)

    转自:http://www.cuiyongzhi.com/post/47.html 我们在微信公众号的后台可以发现微信给我们制定了两种模式,一种是开发者模式(也就是我们一直在做的开发),还有一种模式是 ...

  10. webapi help文档 添加测试功能

    在做webapi项目的时候 webapi为我们提供了help文档,开发者可以参考这个文档,但是这个文档缺少测试功能,如果加上一个测试的功能就更加方便了 于是就研究了下写了一段代码,代码比较简单,只要将 ...