博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Creating and Using Static Libraries for iPhone using Xcode 4.3
阅读量:6862 次
发布时间:2019-06-26

本文共 3918 字,大约阅读时间需要 13 分钟。

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.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.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.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.

转载地址:http://eoqyl.baihongyu.com/

你可能感兴趣的文章
mybatis动态SQL标签的用法
查看>>
学习extjs的布局
查看>>
java-swing模拟实现时钟效果
查看>>
java points[复习]
查看>>
在另一个线程中无法用((CMainFrame *)AfxGetMainWnd())
查看>>
Ignatius and the Princess IV
查看>>
BC#50 1003 The mook jong
查看>>
DEDECMS中,自增长标签
查看>>
JS学习之动态加载script和style样式
查看>>
python快速入门——进入数据挖掘你该有的基础知识
查看>>
42 windows_42_Thread_WaitableTimer 线程 - 等候线程
查看>>
通过xml将传入的字符串转成表格列值
查看>>
优秀安卓开发周刊推荐——My favorite
查看>>
关于centos6上用yum安装mysql后,出现的ERROR 2002 (HY000)的解决办法
查看>>
当在浏览器中输入一个url后回车,后台发生了什么?比如输入url后,你看到了百度的首页,那么这一切是如何发生的呢?...
查看>>
人事管理系统——数据库操作类
查看>>
Bootstrap
查看>>
uva 1339
查看>>
solr之环境配置一
查看>>
wordpress 系列之 header 导航
查看>>