Current location - Health Preservation Learning Network - Slimming men and women - What should I pay attention to when creating an ios static library?
What should I pay attention to when creating an ios static library?
In the development process, we often encounter some parts that are often used in different projects, so it is often a good practice to extract these parts and make them into a static library. There are templates for making static libraries in xcode, and there are many related steps on the Internet, but in practice, there are still many details to pay attention to. The following is a summary of some problems I have encountered.

1. The released version of the compilation library.

In the Management Scheme, simply change the Build Configuration option to Publish. As shown in the figure:

2. Static libraries contain categories.

If you use category in a static library project, you may encounter link problems. The solution is to use the "-all_load" compilation option in both projects that generate static libraries and projects that use static libraries, that is, add "-all_load" to the "Other Linker Flag" option in the corresponding target's Build Settings. Note: This compilation option must be added to projects that use static libraries! ! As for projects that generate static libraries, adding them or not has not been tried, but it is recommended to add this compilation option.

3. SDK versions supported by static libraries

In order to make your static library support the system version of IOS as much as possible, you should select the desired version of IOS in the option of "IOS deployment target". Set the following figure, which is the configuration in my static library project, and the options I modified are circled in red.

4. Automatically copy header files

Add "Copy Header" option under "Construction Phase" of the target corresponding to the project. This option is not available by default. You can add it by clicking the Add Build Phase button below and selecting it. There are three sub-options under this option, namely public, private and project. Click the plus sign below to add the header file in the project to the Project, right-click the corresponding header file and select Move to Public Group. After moving the header file to "Pulic" and compiling the project, the folder named "usr/local/include" will appear in. Locate a file after the project is compiled, where the header file is the header file in the public group. At this point, just copy. A file and the header file under this path to the required engineering file.

reprint