A static library of iOS development. A production tutorial

Source: Internet
Author: User

Brief introduction What is a library?

A library is a collection of program code, a way to share program code

The library can be divided into 2 types depending on the disclosure of the source code

Open Source Library

Open source code, can see concrete implementation

Like Sdwebimage, afnetworking.

Closed Source Library

Unfair open source code, is a compiled binary file, do not see the specific implementation

Mainly divided into: static library, dynamic library

Static libraries and dynamic libraries the existence form of static library and dynamic library

Static libraries:. A and. Framework

Dynamic libraries:. Dylib and. Framework

The difference between static and dynamic libraries in use

Static libraries: When linked, the static library is completely copied to the executable file, and multiple copies are redundant (shown in the image on the left)

Dynamic Library: The link is not copied, the program is dynamically loaded into memory by the system, for program calls, the system is loaded only once, multiple programs are shared, saving memory (pictured on the right)

It is important to note that:

If a self-made dynamic library is used in the project, it cannot be uploaded to AppStore

Make. A

New project, select "Cocoa Touch Static Library"

Add the source code that the library needs to contain

Drag the Li Mingjie Teacher's refresh frame Mjrefresh into the project

Select the. h file that needs to be exposed, and the. m file is automatically compiled into a. a file

Select the real device, then command+b compile, the libmjrefresh.a file changes from red to black

Select Simulator, still command+b, simulator and real machine environment. A file is separate

Right-click on "Show in Finder" to view the created. a file

    • The contents of the Debug-iphoneos folder are used on the real machine.

    • The contents of the Debug-iphonesimulator folder are used on the simulator.

    • If scheme is release mode, the resulting folder starts with release

If you want a. A file to be used on both the real machine and the simulator, you need to merge

Enter the command in the terminal

1 lipo -create Debug-iphoneos/libMJRefresh.a Debug-iphonesimulator/libMJRefresh.a -output libMJRefresh.a

Volume of. A files (in general)

    • For real machines. a > simulator for. A

    • Synthetic. A = = True machine used. A + simulator. A

The Lipo–info libmjrefresh.a can be used to view the type of. A (simulator or real machine)

Use. A

How to use the. A

Drag the. A,. h, resource files directly into other projects

A static library of iOS development. A production tutorial

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.