Brief introduction
What is a library?
A library is a collection of program code, a way to share program code
The library can be divided into 2 types depending on the disclosure of the source code
Open Source Library
Open source code, can see concrete implementation
Like Sdwebimage, afnetworking.
Closed Source Library
Unfair open source code, is a compiled binary file, do not see the specific implementation
Mainly divided into: static library, dynamic library
Static libraries and dynamic libraries
the existence form of static library and dynamic library
Static libraries:. A and. Framework
Dynamic libraries:. Dylib and. Framework
The difference between static and dynamic libraries in use
Static libraries: When linked, the static library is completely copied to the executable file, and multiple copies are redundant (shown in the image on the left)
Dynamic Library: The link is not copied, the program is dynamically loaded into memory by the system, for program calls, the system is loaded only once, multiple programs are shared, saving memory (pictured on the right)
It is important to note that:
If a self-made dynamic library is used in the project, it cannot be uploaded to AppStore
Make. A
New project, select "Cocoa Touch Static Library"
Add the source code that the library needs to contain
Drag the Li Mingjie Teacher's refresh frame Mjrefresh into the project
Select the. h file that needs to be exposed, and the. m file is automatically compiled into a. a file
Select the real device, then command+b compile, the libmjrefresh.a file changes from red to black
Select Simulator, still command+b, simulator and real machine environment. A file is separate
Right-click on "Show in Finder" to view the created. a file
The contents of the Debug-iphoneos folder are used on the real machine.
The contents of the Debug-iphonesimulator folder are used on the simulator.
If scheme is release mode, the resulting folder starts with release
If you want a. A file to be used on both the real machine and the simulator, you need to merge
Enter the command in the terminal
1 |
lipo -create Debug-iphoneos/libMJRefresh.a Debug-iphonesimulator/libMJRefresh.a -output libMJRefresh.a |
Volume of. A files (in general)
The Lipo–info libmjrefresh.a can be used to view the type of. A (simulator or real machine)
Use. A
How to use the. A
Drag the. A,. h, resource files directly into other projects
A static library of iOS development. A production tutorial