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/ ...
随机推荐
- Java文件压缩优化工具(ProGuard) 软件介绍 Soft content
ProGuard是一款免费的Java类文件的压缩.优化.混肴器.它可以帮你删除没用的类,字段,方法与属性,使字节码最大程度地优化,使用简短且无意义的名字来重命名类.字段和方法 .目前eclipse已经 ...
- linux基础(3)
一 正文处理命令及tar命令 使用cat命令进行文件的纵向合并 两种文件的纵向合并方法 : tar命令的功能 : 掌握tar命令的功能:将多个文件(也可能包括目录,因为目录本身也是文件)放在一起存 ...
- 第2章 深入分析java I/O的工作机制(上)
java的I/O操作类在包java.io下,大致分成4组: 所有文件的存储都是字节(byte)的储存,在磁盘上保留的并不是文件的字符而是先把字符编码成字节,再存储这些字节到磁盘.在读取文件时,也是一个 ...
- nios pio interrupt 的使能
关于nios 中的中断,因为要16c550中需要nios的中断环境去测试,所以就用到了中断. 硬件:在nios中添加硬件PIO,但是要使能中断功能.如下图所示: 系统列化,PIO的连接就不说了.但是要 ...
- oracle导入数据和编码问题
配置contrl文件 load data characterset utf8 append into table role_res_gold fields terminated by ';' TRAI ...
- Py修行路 python基础 (八)函数(随时更改)
为何要用函数: 1.解决代码重用的问题 2.提高代码的可维护性,统一维护 3.程序的组织结构清晰,可读性强 定义函数 先定义后使用!!! def funcname(arg1,arg2,.....) ...
- Python 编码机制
python 编码转换 Python的编码机制,unicode, utf-8, utf-16, GBK, GB2312,ISO-8859-1 等编码之间的转换. 常见的编码转换分为以下几种情况: 自动 ...
- 用CSS使图片上下左右都绝对居中于DIV
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Tornado 高并发源码分析之六---异步编程的几种实现方式
方式一:通过线程池或者进程池 导入库futures是python3自带的库,如果是python2,需要pip安装future这个库 备注:进程池和线程池写法相同 from concurrent.fut ...
- Spring Cloud Eureka 5 (服务发现与消费-简单的robbin使用)
通过上述介绍,我们已经有了服务注册中心和服务提供者 下面我们来尝试构建一个服务的消费者 它要完成两个功能,发现服务和消费服务,其中发现服务由eureka客户端完成,消费服务由ribbon完成. rib ...