iOS静态库的制作与引用

iOS静态库的制作与引用

1、Configuring Exported Headers

  To configure whichw headers are exported to clients, select your library project to open the project editor, select the library target to open the target editor, and select the build phases tab. If your library target has a “Copy Headers” build phase, you should delete it; copy headers build phases do not work correctly with static library targets when performing the “Archive” action in Xcode.

  Next you will add a Copy Files build phase for exporting your headers. New static library targets created with Xcode 4.4 or later will come with an appropriately-configured Copy Files phase for headers, so you should check to see if you already have one before creating one. If you do not, press “Add Build Phase” at the bottom of the target editor and choose to “Add Copy Files.” Disclose the new Copy Files build phase and set the Destination to “Products Directory". Set the Subpath to include/${PRODUCT_NAME}. This will copy files into a folder named after your library (taken from the PRODUCT_NAME build setting), inside a folder named include, inside your built products directory. The include folder inside a build products directory is in the default header search path for applications, so this is an appropriate place to put header files. Putting header files inside a folder named after your PRODUCT_NAME will allow you to segregate library headers by library name, for clarity.

  Now select the headers in your static library project which clients of that library will need to import and drag them into the new Copy Files phase. These headers will now be exported to the appropriate location inside your built products directory when you build. Any time you add new headers to your static library which clients will need to import, you should add them to this phase.

  iOS静态库的制作与引用

2、Linking Against Your Library

  Find the “Other Linker Flags” build setting. Add the flag -ObjC to this build setting’s value if it is not already present. This flag will tell the linker to link all Objective-C classes and categories from static libraries into your application, even if the linker can’t tell that they are used. This is needed because Objective-C is a dynamic language and the linker can’t always tell which classes and categories are used by your application code.

  iOS静态库的制作与引用

3、Importing Library Headers

  Your library’s headers are automatically included in your application’s header search path, as they are inside the built product directory’s include directory. Since your library puts its headers in a further directory named after its PRODUCT_NAME build setting, you need to include that directory in your include or import statements when importing that library’s headers. In your application’s source code you should import your library’s headers like this:

#import "LibraryName/HeaderName.h"

4、其它要点

  1)点添加一个.a后,该.a的路径会被自动加入到LibrarySearchPaths,如:

  iOS静态库的制作与引用

    同时LibrarySearchPaths目录下的include目录也会被作为头文件搜索路径。

iOS静态库的制作与引用,布布扣,bubuko.com

iOS静态库的制作与引用

上一篇:IOS 定位服务与地图的应用开发


下一篇:Android - Shared Preference (分享首选项) 详解