What you can get from this article:

  • What are Static Library and Dynamic Library not just in iOS
  • How do they work (in genertal)

Some concepts about library

  • Reduce coupling: if you want to creat a copy of "public code", you have to reduce uncessary coupling of it.
  • Reduce the compile time
  • Reduce the duplicate code

The difference between Static Lib and Dynamic Lib

Library is a compiled library file, usually in binary format. The other users can use it directly with a header file/files. There are two types of libraries:

  • Static library  Linked statically. Related code and addresses will be loaded into main program stright away. It will make the program size bigger  
  • Dynamic library  Linked dynamically. Related code and addresses will be calcuated and then loaded into main program. There will be extra time on this calculation. Will not make the program size bigger.  

Static Library

Static Library in different format .lib under Window, .a under Linux or Mac. The whole static library will be loaded into target and stay still during the compile phrase. The benefits of Static Library the target program runs without any outside dependences, i.e. you can copy this program to other systems if you like. But the drawback is it will make the program bigger.

So it will be a good start if you want to make the program size smaller.

Dynamic library

On the contrary, Dynamic library (.dll under Widnows, .so under Linux and .dylib/.tbd under Mac) will not be loaded into the target program. Instead the target program only load the references during the compile phrase. The Dynamic library will be just loaded while running.

The benefits of Dynamic library:

  • Compared with Static Library, Dynamic library can be used by multiple programs with just one copy.
  • It is quite easy to upgrade the Dynamic library without recompile the whole program

The bad parts of Dynamic library:

  • Extra compile time on Dynamic library/libraries
  • Easy to get the error such as "lib not found" under linux when you are trying to copy the program to other systems but forget the  Dynamic library

iOS Framework

In iOS, Apple is using Framework to package the header files, source files, binary files and resources. Similarly, Framework can be divides into Static Framework and Dynamic Framework.

Before iOS 8, Dynamic Framework is not allowed by Apple. Dynamic Framework is introduced might as the reason of Apple starts support extension. With extension program, it have all the necessary to have to share the same Framework as it used in corresponding app itself.

##Reference