Configuring Your Application

Linking Against Your Library

Select your application project to go to the project editor, then select your application target to go to the target editor. Select the build phases tab. Disclose the “Link Binary with Libraries” phase and click the plus button in that phase. Choose your static library and add it to the phase. Your application will now link against your library.

../Art/linking.png

Select the Build Settings tab in your application target editor. 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.

../Art/buildSettings.png

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"

where LibraryName is the name of your library (the value of its PRODUCT_NAME build setting) and HeaderName is the name of the header you want to import.

Including Library Resources

To include resource files in your application, they should be processed by the application’s Copy Bundle Resources build phase, which does some processing, like compressing png files, and also handles localized resources correctly. Static libraries cannot include resources directly, but a static library project can provide resources which an application can reference and include in its Copy Bundle Resources phase.

To include your library’s resources, first create a new group in your application project for your library’s resources. Next, select all the resource files in the library project and drag them into this new group in the application project. In the Add Files sheet that appears, uncheck the checkbox for “Copy items into the destination group’s folder”, as you want your application to reference the copies of the resource files in the library project, instead of creating separate copies. Check the “Add to targets” checkbox corresponding to your application target, to add these resource files to the application’s “Copy Bundle Resources” build phase.

../Art/addingOptions.png

In the future, if you add new resources to the library project, you must drag the new resource files into your application project as well to create references and add them to the application’s Copy Bundle Resources build phase. If resources are deleted from the library project, the references in your application project will appear as broken references and can be deleted.

Your application is now set up to use your static library.