Files
knowledge-kit/Chapter1 - iOS/1.50.md
2026-02-22 22:12:36 +01:00

2.5 KiB

Static Libraries and Dynamic Libraries

Usually, our Xcode projects depend on some third-party libraries, including: .a static libraries (Static Library) and .framework dynamic libraries (Dynamic Library).

However, simply calling files with the .framework suffix "dynamic libraries" is not precise, because in iOS/macOS development, frameworks are further divided into "static frameworks" and "dynamic frameworks." The differences are as follows:

  • Static framework: Can be understood as a collection of a .a static file + .h public header files + resource files. Essentially it is the same as a .a static library.
  • Dynamic framework: The actual dynamic library in the true sense, generally including a dynamic binary, header files, resource files, etc.

For a Static Library project, its build products are a .a static binary file + public .h header files.

For a Framework project, whether the final build product is a dynamic library or a static library can be chosen in Build Settings -> Linking -> Mach-O Type by setting its value to Dynamic Library or Static Library.

In addition, we know that for a Mach-O binary file, whether static or dynamic, it generally contains several different processor architectures (Architectures), for example: i386, x86_64, armv7, armv7s, arm64, etc.

Xcode handles static libraries and dynamic libraries differently during compilation and linking.

For static libraries, at link time Xcode will automatically select the appropriate architectures from the static library and merge them into the main executable binary for the corresponding processor architecture; and when packaging and archiving, Xcode will automatically ignore architectures in the static library that are not used, for example removing i386, x86_64, and other simulator-only architectures for macOS.

For dynamic libraries, during build and packaging Xcode will directly copy the entire dynamic framework file into the final .ipa. The actual dynamic linking only happens when the app launches at runtime. However, Apple does not allow .ipa files uploaded to App Store Connect to contain simulator architectures such as i386, x86_64 — this will cause an Invalid error. Therefore, for dynamic frameworks in the project, when building a Release production package we typically remove these invalid architectures via commands or scripts.

Finally, how do we add these static/dynamic libraries into an Xcode project?

For ".a static libraries" and "static frameworks", simply drag them into the project and check the "Copy if needed" option. No further configuration is required.