Introduction to the

Library: A piece of compiled binary code that can be used by providing header files to others

  • Static libraries :(.a or.framework) are copied directly into the target program at compile time. Once compiled, the library files are actually useless because the program runs directly from the compiled binary, and the target program runs directly without external dependencies.
  • Dynamic library: the dynamic library is not copied to the target program at compile time. The target program only stores references to the dynamic library, and the dynamic library is not loaded until the program runs. For a fully functional dynamic library, it is a library that can be shared by different programs. As long as it changes, all programs will change, such as system UIKit.framework, etc

In fact, it is not difficult to see from the above essential characteristics, dynamic library is like a global variable, static library is like a local variable. So according to apple’s consistent practice, will not let you have too much permission, in fact for security, so in the Apple world, developers can only make some emasculated version of the dynamic library!

  • Embedded Framework — You can share your Embedded Framework with different processes within the same APP

Q: Isn’t an APP just a process? Why are there different processes in an APP?

A: That’s easy to understand, but technically it’s not true. In terms of iOS, Apple introduced the concept of APP Extension in iOS8. The existence of APP Extension is also the beginning of Apple’s opening of dynamic library. Each APP Extension is an executable binary file independent of the application, but it is not an independent APP. It relies on shared methods and data between Embedded Framework and apps. In addition, the operation mechanism of Swift also needs to use dynamic libraries.

IOS dynamic libraries, static libraries, and framework concepts

Strictly speaking, these three concepts are not in the same dimension. The framework is not a library, it is just a way of packaging, it can be either dynamic library or static library details may refer to

  • Dynamic libraries are dynamically linked libraries (.dll for Windows,.so for Linux,.dylib/.tbd for Mac)
  • Static libraries are static linked libraries (.lib for Windows,.a for Linux, and.a for Mac)
  • Framework – a way of packaging library binaries, headers, and related resource files for easy management and distribution. It can include static libraries, dynamic libraries, or none of them. So it has nothing to do with the nature of static libraries and dynamic libraries.

Dynamic libraries cannot depend on static libraries, they can depend on dynamic libraries, and static libraries can depend on both dynamic libraries and static libraries

Common scenarios Cocoapods

  1. Cocoapods uses static libraries as its default library management mode.
  2. In swift development, if the Swift codebase is included in the Cocoapods, you must use dynamic library management. You need to add use_frameworks to the podfile! field