The difference between IOS static library and Framework

  • 2021-08-21 21:38:57
  • OfStack

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 library and dynamic library.

2. What is the difference between static library and dynamic library?

Static library: When linked, it is completely copied to the executable file, and when used many times, there are multiple redundant copies.

Dynamic library: When the link does not copy, the program run by the system dynamically loaded into memory, for the program call, the system only loaded once, multiple programs shared, saving memory.

3. Static library form in iOS?

. a and.framework

4. Dynamic library form in iOS?

. dylib and.framework

5. Why is framework both static and dynamic?

System.framework is a dynamic library, and our own. framework is a static library.

6. What is the difference between a and. framework?

. a is a pure binary file, and. framework has resource files in addition to binary files.

The. a file cannot be used directly, at least with 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?

It is convenient to share code and use it reasonably.

Realize the modularization of iOS program. Fixed business 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 the third party sdk.

8. Several notes when making static libraries:

1 Note understanding: Whether it is. a static library also. framework static library, we need binary file +. h + other resource file form, the difference is,. a itself is binary file, we need our own with. h and other files to use, and. framework itself has included. h and other files, can be used directly.

2 picture resource processing: Two kinds of static library, 1 is the picture file in a separate. bundle file, 1. bundle name and. a or. framework name is the same. . bundle file is very easy to get, a new folder, renamed it. bundle can, right-click, display package content can add picture resources to it.

3 category is often used in our actual development projects. It is no problem to make category a static library. However, in the project using this static library, there will be a runtime error (selector not recognized) when calling the method in category. The solution is to configure the value of other linker flags to-ObjC in the project using static library.

4 If a static library is complex, Need to expose more. h, you can create a. h file inside the static library (1. The name of this. h file is the same as that of the static library), and then all the. h files that need to be exposed are concentrated in this. h file, while those. h that need to be exposed originally do not need to be exposed again, just need to expose. h.

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: