Create a static library file (. A file)

Source: Internet
Author: User

Create a static library file (. A file)

 

1. Create a static library project:

In xcode, create a new project and select framework & library under Ios. There is a cocoa touch static library. Create a static library project directly next. (For example)

 

 

 

2. compile the project:

Now you can compile the functions to be implemented by the static library (create a file and write code)

 

3. Configure copy files and copy headers for the static library project:

In the build phases set in the project, set (for example), select Add build phases in the lower right corner, and add copy files and copy headers.

Copy files copies the header files required when other projects call the static library to the include folder under products directory. Copy headers sets the target membership of files in the static library project, drag the header file to be exposed to public.

 

 

 

4. Add resource files (including XIB and images ):

Many tutorials on the Internet can be compiled in the previous step, but they are limited to writing some methods (CODE) and cannot add resources. Here we will introduce how to add resource files.

The method is to add all the resource files to a bundle and include them with the static library in other projects. The steps for creating a bundle are as follows:

 

A. Add Bundle: set it in build phases set in the project, and select Add target in the lower right corner to create a target. Here we select bundle (for example) in framework & library under OS X ).

 

 

 

B. We can see that this target template is used under Mac, so we need to modify the configuration so that it can be used under IOS, change the base SDK value under build setting to IOS (it is best to change it to latest .. that) (for example ).

 

 

 

C. Now we can add the resource file to the bundle we just created:

Select the project settings of the bundle you just created. In build phases, add the resources you want to add to link binary with libraries (for example)

 

5. Compile:

Compiler preparation: the static library files generated by our compilation are divided into release and DEBUG Versions. DEBUG Versions can be used for debugging at ordinary times. The release version must be used for release (modified in edit schemes, for example );

 

 

Now you can compile the static library files, header files, and bundle files after compilation are all under the products directory folder.

In addition, the static library also distinguishes between the real machine version and the Simulator version (during compilation, the device version is the real machine version, and if the Simulator version is compiled, we can use the following command on the command line to view the static library information:

Lipo-Info *.

I386 is the Simulator version and armv7 is the real machine version. The following command can combine the library files of the two versions into one:

Lipo-create path1/lib1.a path2/lib2.a-output path3/newlib.

 

6. Create an application that calls the static Library:

7. link the static library: Compile the generated static library file (. file a), the header file, and the bundle file are added to the new application. library a is added to the link binary with library of build phases set in the project, and bundle is added to the copy bundle resources of build phases set in the project.

So far, we have added the static library to the application. Introduce the header file where you need to use the method in the library, and then you can call the method in it.

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.