Create your own static library in iOS development. A, resource pool. Bundle,. Framework

Source: Internet
Author: User

First, what is the library

libraries are actually a way of sharing code, primarily for code reuse and source hiding, usually in dynamic and static libraries.

Static Library: A full copy of the link is made to the executable file, and multiple copies are used multiple times.

Dynamic Library: The link is not copied, the program is dynamically loaded into memory by the system, for program calls, the system is only loaded once, multiple programs shared, saving memory space.

Ii. what is. A,. Bundle,. Framework

in iOS, static libraries exist in the form of. A and. Framework, and dynamic libraries exist in the form of. Dylib and. Framework.

The reason for this is that the framework can be either a dynamic or a static library, because Apple prohibits user-level apps from using dynamic libraries, but instead uses dynamic libraries on their own, which results in system-level iOS. The framework is a dynamic library, a user-level. Framework is a static library.

There is not much difference between the two. A is a pure binary file,. A files cannot be used alone, at least with. h files, and. The framework, in addition to binaries, contains resource files (header files, plist, and so on), and the. Framework can be used alone because it contains a header file.

. A and. Framework two static libraries, usually the need to use a picture or xib file in a bundle file, and the bundle file name is the same as the name of the. A or. Framework. There is a special introduction to the method of making bundle files.

Third, the necessity of using static library

1>. Sharing and reuse of code

2>. Modularity of the program

3>. Code-behind when sharing to others code base

4>. Developing a third-party SDK

Iv.. A static library file

1. Click Create Project

2. Coding in. m and. h

3, according to ARMV7 and arm64 packaging two. A to merge

Merge two. a Files

lips-create/users/tiansha/desktop/libtestlibrary.a/users/tiansha/desktop/demo/shengshihuihai/shengshihuihai/ resource/libtestlibrary.a-output/users/tiansha/desktop/libtestlibrary2.a

The emulator package and the true package can also be combined using this method.

4. Import into the project after merging, and import the. h file into the project together with the. a file

5, compile the project, the testlibrary can be called. A method

Summary:. A files need to be combined with the emulator and the real machine files before they can be used in the project, to avoid the problem of high development costs caused by switching.

V. Resource pool. Bundle

1. The characteristics of bundle resource Library

The bundle is static, that is, the resource file that we include into the package is not compiled as a resource bundle without participating in the project. It also means that the bundle package cannot contain executable files. It is only as a resource and is parsed into a specific 2 binary data.

2, new. Bundle

3. Add the resource files that you need to compile in the bundle.

Of course, the default configuration is also possible, if you need a specific optimization or specific path configuration, you can proceed to the 4th step below configuration. 4. Make optional SettingsResource bundles only need to be compiled without installation 5. Build the. bundle file, import the project 6. Call Mode  

Uiimageview *image = [[Uiimageviewalloc]initwithframe:cgrectmake (0,0,320,480)];

Image.backgroundcolor = [Uicolorredcolor];

Image.image = [uiimageimagenamed:@ "Testbundle.bundle/contents/resources/1.png"];


v.. Framework   1. Create 2, Build phases-Headers, you can see that there are three options, respectively, is public,private,project; drag the. h file that needs to be exposed to the public, leaving the remaining ones invisible, that is, hidden files, Put in Project 3. All the. h files that need to be exposed are introduced with #import<testframework/testlibrary.h>, keeping in mind that all. h files that need to be exposed must be written in a given. h file, Otherwise, the generated. Framework will have a warning when referenced. 4. Create a new target and select other->aggregate 5. Select the new target, click Build Pharas, select +,new Run script Phase in the upper-left corner to add the script scripts are used to merge the framework, the real machine and the emulator version, and the ARMv7 armv7s arm64 and other different architectures

# Sets the target folders and the final framework product.

# if the project name and the framework's target name are different, customize the Fmkname

# example: Fmk_name = "Myframework"


# Install Dir'll is the final output to the framework.

# The following line create it at the root folder of the current project.


# working dir would be a deleted after the framework creation.




#-configuration ${configuration}

# Clean and Building both architectures.

Xcodebuild-configuration "Release"-target "${fmk_name}"-sdk Iphoneos clean Build

Xcodebuild-configuration "Release"-target "${fmk_name}"-sdk Iphonesimulator clean Build

# cleaning the oldest.

If [-D "${install_dir}"]


Rm-rf "${install_dir}"


Mkdir-p "${install_dir}"

Cp-r "${device_dir}/" "${install_dir}/"

# Uses The Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.

Lipo-create "${device_dir}/${fmk_name}" "${simulator_dir}/${fmk_name}"-output "${install_dir}/${fmk_name}"

Rm-r "${wrk_dir}"

Open "${srcroot}/products/"

6. Select the first target in targets, click Build Setting, Mach-o Type, select the static Library, there will be a problem here, It is impossible to use on iphone5c. Framework, which we need to add armv7s in build Setting-architectures->architectures

  7, select Aggregate, compile, automatically open the product folder after successful compilation   8, open the terminal, you can view the supported architecture


9, the Import project can be used

Note: The version of Xcode that is running is 7.3

Create your own static library in iOS development. A, resource pool. Bundle,. Framework

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: 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.