The difference between IOS static library and Framework
1. What is a library?
Library is a way to share program code, which is generally divided into static libraries and dynamic libraries.
2. What is the difference between static libraries and dynamic libraries?
Static library:It is copied to the executable file in full at link time, and after multiple use, it will have multiple redundant copies.
Dynamic library:It is not copied during linking. The program is dynamically loaded into memory by the system when it is run. It is for program calls. The system only loads it once. It is shared by multiple programs, saving memory.
3. What is the static library form in iOS?
.a and .framework
4. What is the dynamic library form in iOS?
.dylib and .framework
5. Why is framework both a static library and a dynamic library?
The system's .framework is a dynamic library, and the .framework we have created ourselves is a static library.
6. What is the difference between a and .framework?
.a is a pure binary file. In addition to binary files, there are resource files in the .framework.
The .a file cannot be used directly, at least it must be accompanied by the .h file, and the .framework file can be used directly.
.a + .h + sourceFile = .framework。
It is recommended to use .framework.
7. Why use static libraries?
Convenient to share code and easy to use.
Implement modularization of iOS programs. Fixed services can be modularized into static libraries.
Share your code base with others, but don't want others to see the implementation of your code.
The need to develop third-party SDKs.
8. A few points of note when making static libraries:
1 Note: Whether it is the .a static library or .framework static library, what we need is the form of binary files +.h + other resource files. The difference is that .a itself is a binary file, and we need to match .h and other files ourselves to use it. .framework itself already contains .h and other files and can be used directly.
2 Processing of image resources: Two types of static libraries generally place the image file separately in a .bundle file. Generally, the name of .bundle is the same as the name of .a or .framework. The .bundle file is easy to make. Create a new folder and change it to .bundle. Right-click to display the package content and add image resources to it.
3 category is often used in our actual development projects. There is no problem in making category into a static library. However, in projects using this static library, there will be a run-time error in which the method cannot be found when calling the method in category. The solution is: configure the value of other linker flags to -ObjC in projects using static libraries.
4 If a static library is very complex and needs to be exposed, you can create a .h file inside the static library (usually the name of this .h file is the same as the name of the static library), and then concentrate all the .h files that need to be exposed in this .h file. Those .h that originally needed to be exposed do not need to be exposed anymore, just expose .h.
Thank you for reading, I hope it can help you. Thank you for your support for this site!