Package. a static library in iOS development, for example, ios..

Source: Internet
Author: User

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!

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.