Creating and Using Static Libraries for iPhone using Xcode 4.3
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的更多相关文章
- 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 ...
- 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 ...
- 「操作系统」:Linker Use static Libraries
While static libraries are useful and essential tools, they are also a source of confusion to progra ...
- Openssl - Static libraries (w32, mingw) 以及对Qt静态编译时的设置
Openssl static libraries created for Windows 32bit using MinGW compiler Compiled with: ./Con ...
- Building Objective-C static libraries with categories
Q: How do I fix "selector not recognized" runtime exceptions when trying to use category m ...
- 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 ...
- 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 ...
- iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址(2014年2月19日更新版)
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3496069.html 编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 ...
- iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译
编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 1 苹果API常用英语名词---iOS-Apple苹果官方文档翻译 http://www.cnblogs.com/ChenYilong/p/ ...
随机推荐
- F4NNIU 学习目录 (2018-08-22)
F4NNIU 学习目录 语言 C 语言 C 语言程序设计进阶 在线刷题 https://leetcode-cn.com/problemset/all/ 工具 Git 版本管理 在线教程 在线教程
- 插耳机对orientation sensor的影响
偶然发现,耳机孔插上耳机对手机的磁感应器有非常大的影响. 具体影响的方式和解决的方法,慢慢研究下
- 机器人操作系统(ROS)教程22:ROS的3D可视化工具—rviz
rviz是ROS中的一个3D可视化工具,有了它就可以把你用代码建的机器人模型转化为可视的3D模型. 首先需要安装: rosdep install rviz 然后编译rviz: rosmake rviz ...
- eclipse配置项目部署到到本地tomcat
一.发现问题 在eclipse中新建Dynamic Web Project,配置好本地的tomcat并写好代码后选择Run on Server,但运行后发现在tomcat的安装目录下的webapps并 ...
- mongo数据排序和分页显示
数据排序 使用sort()1 升序-1 降序自然排序 数据插入的顺序$natural db.stu.drop(); db.stu.insert({,,"address":" ...
- POJ2142(扩展欧几里得)
The Balance Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5991 Accepted: 2605 Descr ...
- HTML简历
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JavaScript笔记——事件
事件一般是用于浏览器和用户操作进行交互.最早是 IE 和 Netscape Navigator 中出现, 作为分担服务器端运算负载的一种手段.直到几乎所有的浏览器都支持事件处理.而 DOM2 级规范开 ...
- cocoa 线程操作
在Cocoa 中创建线程使用NSThread类的detachNewThreadSelector: toTarget:withObject:方法 NSPort *port1 = [NSPort port ...
- 【phonegap】IOS按HOME键,程序进入suspended状态,再调出,界面出现文字丢失问题
发现丢失的都是时间类型的,把日期型改成 yyyy年mm月dd日 时间从冒号表示(12:00)改成中文表示,12点00分,就不再丢失了. 未找到真正原因