1. New. A Static library project
you need to select a Static Library static library project template to create a new project, such as:
New Static Library project
Implement the classes that need to be packaged, such as:
Implementing classes that need to be packaged 2. Set the header file to be exposed
Add Headers , steps:---- TARGET Build Phases + New Headers Phase ---, such as:
Then find Heaers(0 items) a column, dot + add header file, such as:
Then add the header files that need to be exposed Encryption.h , such as:
When added is complete, Encryption.h it appears in Project a column that needs to be manually dragged into Public a column for public use, such as:
After being dragged Public in, the header file is the public header file, such as:
3. Set Scheme
Choices Edit Scheme , such as:
Select Debug the mode, such as:
4. Compile the emulator version of the. a static library
Select an emulator, such as:
After the simulator is selected, the compilation succeeds and the Products libEncryption.a color changes from red to black, such as:
5. Compile the. A static library of the real machine version.
Select a real machine, such as:
After selecting the real machine to start compiling, after the successful compilation, Products the libEncryption.a red color will also be changed to black.
6. Merging the mock version and the real machine version of the static library
Select libEncryption.a , right-click Show in Finder to select, such as:
After entering the Finder, you can see the compiled emulator and the real machine version of the. A static library, such as:
Open the terminal and use the command line for version merging, in the following format:
"真机版本.a静态库路径" "模拟器版本.a静态库路径" -output "合并后的.a静态库路径"
Notice that there are spaces in the middle.
Enter the command line in the terminal, such as:
When the terminal executes successfully, a merge version of the. A static library is generated, such as:
7. Test the Static library
Create a new project, libEncryption.a and Encryption.h drag files into the project, such as:
In ViewController.m introducing the Encryption.h header file, call the Encryption.h exposed encryption method, ViewController.m in the code below:
#import"ViewController.h" #import "Encryption.h" @interface viewcontroller () @end @implementation viewcontroller-(void) viewdidload {[super viewdidload]; //calls the encryption method in encryption nslog (@ "- ----%@ ", [Encryption Md5encryptwithstring:@" Hello "]);} -(void) didreceivememorywarning {[super Didreceivememorywarning]; //Dispose of any of the resources that can be recreated.} @end
The debug window successfully outputs printing information such as:
At this point,. A static library is finished!
Reference Link: http://www.jianshu.com/p/add59ec093b6
Packaged in iOS. A static library