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/ ...
随机推荐
- FastAdmin 学习线路 (2018-09-09 增加 Layer 组件)
FastAdmin 学习线路 (2018-09-09 增加 Layer 组件) 基础 HTML CSS DIV Javascript 基础 jQuery php 基础 对象 命名空间 Apache 或 ...
- MATLAB 02
对一组数据作线性回归,并绘图 clear all; % 输入数据x和y x = [ ]'; y = [11 13 14 15 16 18 20 21 22 25 26 28 29 31]'; x = ...
- mysql特性及部署规范
--分支版本,mysql对cpu,内存,io子系统资源利用特点--oracle mysql,mariadb,percona server--部署规范建议,系统安装,mysql安装,其他规范互联网业务为 ...
- java 最差实践
HashMap size 陷阱: 错误写法: Map map = new HashMap(collection.size()); for (Object o : collection) { map.p ...
- Zabbix自定义监控网站服务是否能够正常响应
监测tcp连接数文件名: /etc/zabbix/zabbix_agentd.conf.d/count_tcp.conf UserParameter=count.tcp,netstat -s|g ...
- vs2017 android demo
vs2017自安装以后就没怎么打开过,虽然12出的时候用10,15出的时候用13,17出的时候用15,但我依然坚持不用也装上再说的理念. 1.vs2017开发IOS和Android安装所必不可少的,u ...
- Centos7.2:搭建Ceph管理系统Inscope
0.引言 好几天没有更新博客了,这几天分配有任务:calamari与inscope管理系统调研.下面就管理系统的环境搭建做一个总结,总结一下搭建流程以及搭建过程中遇到的一些问题.calcamari的搭 ...
- java成神之——MySQL Connector/J 的基本使用
使用示例 DBCP连接池 结语 使用示例 public class demo { static Connection con = null; static Statement st = null; s ...
- Java中 单例(Singleton)的两种方式
第一种(饿汉式单例模式):在声明变量时实例化 public class Singleton { //静态初始化自动实例化 private static Singleton instance = new ...
- Ubuntu 17.04 允许使用root ssh登录
用ubuntu 17.04部署完docker后,用winscp去管理系统上的文件发现默认的管理员账号权限不够,想重新用root登录,发现一只被服务器拒绝(permission denied).已经执行 ...