1. What is a library
A Library is simply a piece of compiled binary code that, with a header file, can be used by others.
When do we use libraries?
- In one case, some code needs to be used by others, but we don’t want others to see the source code, so we need to wrap it in a library, exposing only the initial files. (Some introduced third-party libraries)
- For some code that will not make major changes, we want to reduce the compilation time, we can package it as a library, because the library is already compiled binary, just need to Link when compiling, won’t waste compilation time. (Some relatively stable tool classes, or very stable function modules)
2. Concept introduction
Dynamic libraries, static libraries, and the framework are not in the same dimension.
1, the framework
The framework is not a library, it’s just a package that can be either dynamic or static. Package library binaries, header files, and related resource files together for easy management and distribution, and have nothing to do with the nature of static libraries.
2. Static libraries
Static libraries (statically linked libraries) end with. A and. Framework. So static libraries are copied directly into the target program at compile time, and the code does not change in the program
Advantages: After compiling, the library file is useless, the target has no external dependencies and can be run directly
Disadvantages: The target size will increase
3. Dynamic library
Dynamic libraries (dynamically linked libraries) end with the.dylib or.framework suffix. In contrast to static libraries, dynamic libraries are not copied to the target program at compile time, which stores only references to dynamic libraries. The dynamic library is not actually loaded until the program runs.
Advantages: The size of the target program is not affected, and the same library can be used by multiple programs (for this reason, dynamic libraries are also called shared libraries). Also, features that are loaded only at runtime allow us to replace libraries at any time without having to recompile the code.
Disadvantages: Dynamic loading incurs a performance penalty, and using dynamic libraries makes the program dependent on the external environment. If your environment lacks a dynamic library or has an incorrect version of the library, the program will not run (the beloved Lib Not Found error on Linux).
3 Common ios libraries
System Dynamic library Dynamic Framework
Frameworks provided by the system are dynamic libraries, such as UIKit.framework, with all the features of dynamic libraries.
User dynamic library Embedded Framework
Dynamic library is a dynamic library that can be created by users. It is limited by the iOS platform (signature mechanism and sandbox mechanism). It has some dynamic features, such as:
- Embedded Framework can be shared between Extension and APP executables, but not between different apps like a system’s dynamic library
- The system Framework does not need to be copied to the target application, and the Embedded Framework must eventually be copied to the APP.
Static library Tatic Framework
It is equivalent to header files + resource files + binary code. It has the properties of a Static library.
Static libraries are common tool libraries in our componentization
Dynamic libraries in ios, static libraries ios makes static libraries