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. 利用bat合并两个hex文件

    单片机程序如果有IAP功能的话,就会生成两个hex文件,一个是Boot,一个是App,如果给让生产烧录两个文件,就会降低生产效率,所以在烧录前最好将两个文件合并成一个文件,烧录一次即可,合并方法如下: ...

  2. 关于ListView和GridView的应用

    这两篇博文分别讲的很好: ListView: http://www.cnblogs.com/noTice520/archive/2011/12/05/2276379.html GridViw: htt ...

  3. 理解Windows消息循环机制

    理解消息循环和整个消息传送机制对Windows编程十分重要.如果对消息处理的整个过程不了解,在windows编程中会遇到很多令人困惑的地方. 什么是消息(Message)每个消息是一个整型数值,如果查 ...

  4. nextSibling VS nextElementSibling

    2. nextSibling vs nextElementSibling { //FF { 在Firefox中,link2的nextSibling并不是link3,因为两者之间有一个换行符. 这被认为 ...

  5. android欢迎页

    在进入程序后,会在一个页面停留几秒然后自动跳转到程序主界面,这个页面就是欢迎页. 首先新建个java文件,给他起名叫做WelcomeActivity 在里面我们通过一个匿名类new Handler,在 ...

  6. 实例甜点 Unreal Engine 4迷你教程(2)之用C++改变Image小部件的颜色

    完成本迷你教程之前,请前往完成以下迷你教程: ·实例甜点 Unreal Engine 4迷你教程之如何用C++将纹理绘制在UserWidget的Image小部件上: 目标:实现UMG中的此功能: 在上 ...

  7. Apache+PHP多端口多站点

    # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the defaul ...

  8. thinkphp模板中for循环与switch的使用

    1.for用法 <for start="开始值" end="结束值" comparison="" step="步进值&quo ...

  9. oracle显示数据库名和表名

    oracle查看表名 select table_name from user_tables; select table_name from dba_tables; select * from all_ ...

  10. springboot成神之——mybatis在spring-boot中使用的几种方式

    本文介绍mybatis在spring-boot中使用的几种方式 项目结构 依赖 WebConfig DemoApplication 方式一--@Select User DemoApplication ...