Introduction:
This article records the problem summary and solutions when using static libraries in IOS.
How to Create a static Library:
1: detailed steps for the master project to associate with the static database
I. Associate the static library with the project
2. When writing code for a project, you must be prompted with the header file in the static library.
3. To ensure that the latest static library can be accessed every time after code compilation and running in the static library is modified, perform the following settings:
Full path needs to select the static library file generated after the specific compilation in the deriveddata folder, so that the latest static library file can be used every time.
Ii. solution to the problem that the static library cannot use resource files:
First, all the resource files are still attached to the static library, and then you can import the reference of the resource file to the project you want to use.
Drag the resource file you want to use to the project and the settings shown in figure are as follows:
3. When the static library uses resources of other static libraries, you can directly set the header search path to ensure that these static libraries are referenced by the main project.
4. Solve the crash generated by using category (category) in the static library
You can solve the problem by setting the following settings in the main project that calls the static Library:
Project> build Settings> Other linker flags:-All_load
Note: This setting method will load the category of all static libraries and frameworks related to the main project.
:
References:
Http://blog.csdn.net/leonpengweicn/article/details/6799994
For details about how to use category, refer:
Http://blog.csdn.net/sanpintian/article/details/7406180
Http://www.54xue.com/w/70/n-30670.html
To save variables in a category, refer to the following article:
Http://www.cnblogs.com/liping13599168/archive/2012/09/13/2682664.html
Solution: (set the static library to a single one to load category ).
Reference post:
Http://dev.voicecloud.cn/bbs/forum.php? MoD = viewthread & tid = 4154 & extra = & page = 1
1. Remove the-objc-all_load parameter (this parameter will force all static link libraries to load the category );
2. Load the static libraries of three20 one by one, that is, modify the link parameters (Other linker flag) as follows:
-Force_load $ (built_products_dir)/libthree1_a
For example:
5. If you switch the entire file to another directory, xcode may generate a warning that the directory cannot be found during compilation, for example:
The solution is as follows:
Check whether the path of library search paths is correct:
6. Unknown class myclass in interface builder file. Solution
SetOther linker flagOf
-All_load
If-all_load is not set when a static library is used, the main project does not check whether the referenced framework is referenced during compilation ).
However, it is okay to use it, but the code that requires the framework to be executed will crash. In addition, XIB will report that the corresponding class cannot be found unless it is actively called in the code.
7. The best solution for resource usage and management in the static library.
Use bundle to use and manage resources.
The procedure is as follows:
1: create a new folder and name it XXX. Bundle. After Mac identifies it as a bundle.
2: copy the related resources used by the static library to the bundle.
3: When writing code, the path is changed as follows:
[UIImage imageNamed:@"PullTableView.bundle/arrowhead_up.png"]
4: This is my suggestion: Put the bundle in the directory of the static library, and do not copy it to the execution area when dragging it to the main project. As shown in the settings: