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. BZOJ3790:神奇项链

    浅谈\(Manacher\):https://www.cnblogs.com/AKMer/p/10431603.html 题目传送门:https://lydsy.com/JudgeOnline/pro ...

  2. loj 572 Misaka Network 与求和 —— min_25筛

    题目:https://loj.ac/problem/572 推式子:https://www.cnblogs.com/cjoieryl/p/10150718.html 又学习了一下杜教筛hh: 原来 u ...

  3. erlang配置三方库

    暴力的: 直接下载解压以后放到erlang的lib目录,比如/usr/local/Cellar/erlang/17.3/lib/erlang/lib 和谐的: 在用户名下建立.erlang文件 在里面 ...

  4. bootstrap 设置表格固定宽度 内容换行

    在项目中开发的时候用的bootstrap,但是有些表格的内容 会显示的很长 那么我第一时间想到的就是 修改td或者th的width,但是我设置了 之后不起作用 于是百度找到了解决方法: 学习源头: h ...

  5. 【转】使用JMeter 完成常用的压力测试(三)

    使用JMeter 完成常用的压力测试 发布时间: 2008-9-27 15:33    作者: 未知    来源: 网络转载 字体:  小  中  大  | 上一篇 下一篇 | 打印  | 我要投稿 ...

  6. Excel开发学习笔记:文件选择控件、查找匹配项、单元格格式及数据有效性

    一个自用的基于excel的小工具. , ), .Cells(, ))          sysKpiRow.Interior.ColorIndex =  ).value = , )           ...

  7. 第三章 深入分析Java Web中的中文编码问题

    3.1 几种常见的编码格式 3.1.1 为什么要编码 一个字节 byte只能表示0~255个符号,要表示更多的字符,需要编码. 3.1.2 如何翻译 ASCII码:有128个,用一个字节的低7位表示. ...

  8. VS加载项目时报错 尚未配置为Web项目XXXX指定的本地IIS

    网上找的几个方法都不行 最后自己解决了.首先打开该项目得csproj文件,找到<ProjectExtensions>这个标签,是在最后部分,然后把<UseIIS>True< ...

  9. VMware80端口映射

    目标是外网访问80端口,然后映射到虚拟机的80端口,80映射到80. 1.首先80端口是最常用的端口,要确认主机80端口是否被占用,如果被占用,停止或者修改占用80端口程序. 2.80端口默认防火墙是 ...

  10. 获取Request.Form所有内容

    string wwww = "";        for (int i = 0; i < Request.Form.Count; i++)        {          ...