Package. a static library in iOS development, for example, ios..
1. Create a static library project
You need to select the Static Library project template to create a project, such:
Create a static library project
Classes to be packaged, such:
Classes to be packaged
2. Set the header file to be exposed
Add Headers by following the following steps: TARGET-> Build Phases-> point + number-> New Headers Phase, for example:
Find the Heaers (0 items) column and click + to add the header file, for example:
Add the header file Encryption. h to be published, for example:
After adding the file, Encryption. h will appear in the Project column. You need to manually drag it into the Public column to make the file Public. For example:
After being dragged in, the Public header file is the Public header file, for example:
3. Set Scheme
Select Edit Scheme, for example:
Select the Debug mode, for example:
4. Compile the. a static library of the simulator version
Select a simulator, for example:
Select the simulator and start compilation. After compilation is successful, libEncryption. a in Products will change from red to black, for example:
5. Compile the. a static library of the real machine version
Select a real machine, for example:
Select the real machine and start the compilation. After the compilation is successful, the libEncryption. a in Products will also change from red to black.
6. Merge static libraries of simulated and real-machine versions
Select libEncryption. a and right-click Show in Finder, for example:
After entering the Finder, you can see the compiled simulator and the. a static library of the real machine version, such:
Open the terminal and use the command line to merge versions. The specific format is:
Lipo-create "real machine version. a static library path" "Simulator version. a static library path"-output "merged. a static library path"
Note that there must be spaces in the middle.
Enter the command line in the terminal, for example:
After the terminal is successfully executed, a. a static database of the merged version is generated, for example:
7. Test the static library
Create a project and drag libEncryption. a and Encryption. H files into the project, for example:
Introduce the Encryption. h header file in ViewController. m and call the Encryption method exposed by Encryption. h. The code in ViewController. m is as follows:
# Import "ViewController. h "# import" Encryption. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // call the NSLog (@" ----- % @", [Encryption md5EncryptWithString: @ "hello"]);}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end
The debugging window successfully prints information, such:
So far, the. a static library has been created!