The and. Framework productions of the IOS Static library

Source: Internet
Author: User
Tags uikit

What is a library? Library is a collection of program code, is a way to share program code according to the public situation of the source code, the library can be divided into 2 types of open source libraries to expose sources, can see concrete implementation such as Sdwebimage, afnetworking closed Source Library unfair open-sourced code, is compiled binary files, Not see the implementation is mainly divided into: static library, dynamic library

Static libraries and the existence of dynamic libraries static libraries:. A and. Framework Dynamic libraries:. Dylib and. Framework static libraries and dynamic libraries in use the Difference static library: When linking, the static library is completely copied into the executable file, Multiple redundant copies are used multiple times (shown on the left). Dynamic Library: Link is not copied, the program is dynamically loaded into memory by the system, for program calls, the system is loaded only once, multiple programs are common, save memory (the image shown on the right)


Select "Cocoa Touch Static Library"

Enter a static library name

Add the source code that the library needs to contain


Select the. h file that needs to be exposed, and the. m file is automatically compiled into a. a file

Select the real device, then command+b compile, the libmjrefresh.a file changes from red to black


Select Simulator, still command+b, simulator and real machine environment. A file is separate

Right-click on "Show in Finder" to view the created. a file


The contents of the Debug-iphoneos folder are used on the real machine.
The contents of the Debug-iphonesimulator folder are used on the simulator.

If scheme is release mode, the resulting folder starts with release



in Terminal input command
< Span style= "COLOR: #0000ff" >lipo-create debug-iphoneos/libmjrefresh.a Span style= "COLOR: #993366" > debug-iphonesimulator/libmjrefresh.a -output libmjrefresh.a
Blue section is fixed directive
red , purple is a real machine and simulator. Path to a file
orange is the path to the synthesized. A file

Volume of. A files (in general)
For real machines. a > simulator for. A
Synthetic. A = = True machine used. A + simulator. A


The lipo–info libmjrefresh.a can be used to view the type of. A (simulator or real machine)


How to use the. A
Drag the. A,. h, resource files directly into other projects


Select "OS X"-"Framework & Library"-"Bundle"


Enter a static library name


The project was created based on OS X, so you have to modify the program environment for iOS


Modify Packaging


Modify Info.plist


Comment out the contents of the PCH file


Add the source code that the library needs to contain

Add the. h file that needs to be exposed


Add the. h file that needs to be exposed and put it under public


The next steps are the same as. A, select the real machine and the simulator respectively, Command+b
The. Framework under the real machine and simulator is also used separately

The resulting framework is in the cache folder of Xcode
/users/User name/library/developer/xcode/deriveddata/project name/products

You can use the Lipo directive to merge under a terminal. Framework, need to merge a file inside the framework


Drag and drop the entire. Framework into other projects under the Frameworks folder
Then include the main header file:#import <MJRefresh/MJRefresh.h>


Handmade . The framework is too complex to make it easier with open source templates

Template Address
Https://github.com/kstenerud/iOS-Universal-Framework

Install the template
Enter the ios-universal-framework/fake Framework folder under Terminal
Execution instructions ./install.sh


After installing the template, completely restart Xcode

Finally, the structure of the. Framework can be adjusted

Either the. A static library or the. Framework static Library, the final requirement is:
binary files +. H + Other resource files

Differences in usage of. A and. Framework
. A itself is a binary file that needs to be equipped with. h and other resource files to use
The framework itself already contains. h and other resource files that you can use directly

Processing of picture Resources
If the static library uses the picture resources, usually put in a bundle file, the bundle name is generally the same as the. A or. Framework names
Bundle creation: Create a new folder, modify the extension to. bundle, right-click the bundle file, display the package content, you can put things in the bundle file


Multi-file processing
If the static library needs to be exposed. h more, consider creating a primary header file
( general primary header file with same name as Static library )
Include all other. h files that need to be exposed in the main header file
When using a static library, you only need to #import the primary header file
In fact Apple is doing this, for example:#import <UIKit/UIKit.h>

Why the framework is both a static library and a dynamic library
The. Framework of a system is a dynamic library
We built it ourselves. The framework is a static library

The static library contains the Category
If the static library contains Category, sometimes the "method cannot find" error is reported in a project that uses a static library (unrecognized selector sent to instance)
Solution: Configure other Linker Flags as -OBJC in a project that uses a static library

The and. Framework productions of the IOS Static library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.