Using a third-party class library in iOS
Some third-party libraries are often used in project development, usually in two ways: one is to copy all of the. h and. m files directly into the project, and the other is to drag the. Xcodeproj into the project to generate a static link library and reference it.
Method One: Copy all the source files directly into the project
This approach is to copy all the source files from the third-party class library to the project, and drag all the. h and. m files directly into the Xcode project. If a third-party class library references some system-brought class libraries, additional references to those class libraries are required in the project.
If ARC is enabled for the current project and the referenced third-party class library does not use arc, then the. m file for the third-party class library will need to be found in the Targets - Build parses of the project information and added to them - Fno-objc-arc tag.
For a third-party class library that uses arcs for references to projects that do not have arc enabled, you need to add the -fobjc-arc tag to the. m file for the third-party class library.
In addition, in the source code can be a compiler directive __has_feature (OBJC_ARC) to detect whether the project uses arc, see http://clang.llvm.org/docs/ Languageextensions.html#langext-has-feature-has-extension.
Method Two: Reference. xcodeproj generate a static link library and reference
First, put the third-party class library in Xcode. xcodeproj file to the current project; If a third-party class library encapsulates some resources in the. bundle file, then the. bundle file needs to be dragged into the project with. Xcodeproj.
Then, in the project's targets–summary–linked frameworks and Libraries or in targets–build phases–link Binary with Librar IES adds a static link library reference generated by a third-party class library.
Next, you also need to include the header file path of the third-party class library in the User header Search Paths parameter of the targets–build settings–search Paths , which can be an absolute path such as:/ Users/libpath, or it can be a relative path (as opposed to the current project folder) such as: /**。
Finally, some static link library references may require additional markup to be added in the other Linker Flags parameter of targets–build settings–linking :-OBJC , –all_load this type of tag.
Through the above steps, it is generally possible to compile successfully.
There are, of course, some exceptions:
- The current project and the third-party class library use additional third-party libraries at the same time, which requires extra processing to compile successfully: the . Xcodeproj project in the referenced third-party class library –targets–build phases Compile Sources and Copy Headers Remove the duplicate. m and. h files.
- Some systems referenced by third-party class libraries have their own class libraries, and if there are no references in the project, they can also cause compilation errors, and you will also need to reference some of the system's own class libraries referenced by the third-party class library in your project. For example, a third-party class library that references Quartzcore.framework, and quartzcore.framework that are not referenced in a project can cause compilation errors, and you need to reference quartzcore.framework in your project as well.
iOS uses a third-party framework note