In iOS development, add a new. Framework to your project

Source: Internet
Author: User

First you need to understand the concepts of static and dynamic libraries, and the framework in iOS

The difference between a static library and a dynamic library

First of all to see what is a library, the library is plainly a compiled binary code, plus a header file can be used by others.

When will we use the library? One situation is that some code needs to be used by others, but we do not want others to see the source code, it needs to be packaged in the form of a library, only exposed files. Another situation is that for some code that does not make big changes, we want to reduce the compile time, we can package it into a library, because the library is already compiled binary, compile the time only need Link, do not waste compilation time.

The above mentioned that the library in use when the need to link,link the way there are two, static and dynamic, resulting in a static library and dynamic library.

Static Library

Static libraries are static link libraries (. lib,linux and Mac under Windows. a). It is called static, because the static library will be copied directly in the compilation, copy to the target program, this code in the target program will not be changed.

The benefits of a static library are obvious, and when the compilation is complete, the library file actually doesn't work. The target program has no external dependencies and can be run directly. Of course, its shortcomings are also obvious, is to use the target program's volume increases.

Dynamic Library

The dynamic library is the dynamic-link library (. dylib under. Dll,linux under Windows. So,mac). In contrast to a static library, a dynamic library is not copied to the target program at compile time, and only references to the dynamic library are stored in the target program. When the program is running, the dynamic library is actually loaded in.

The advantage of a dynamic library is that it does not need to be copied to the target program, does not affect the volume of the target program, and the same library can be used by multiple programs (for this reason, the dynamic library is also known as a shared library ). At the same time, the feature that is loaded at compile time also allows us to replace the library at any time without recompiling the code. The main problem of dynamic library is that dynamic onboarding brings some performance loss, and the use of dynamic libraries also makes the program dependent on the external environment. If the environment lacks a dynamic library or the library version is incorrect, it will cause the program to fail to run (Linux does not found error).

IOS Framework

In addition to the above mentioned. A and. Dylib, the Mac Os/ios platform can also use the Framework. The Framework is actually a packaging method that packs the library's binaries, header files, and related resource files together for easy administration and distribution.

Prior to iOS 8, the iOS platform did not support the use of dynamic frameworks, and the framework that developers could use was only Apple's own uikit.framework,foundation.framework. This limitation may be due to security considerations (see the discussion here). In other words, because IOS applications are running in the sandbox, different programs can not share code, while the dynamic download code is also banned by Apple, there is no way to play the advantages of dynamic library, in fact, there is no need for dynamic library.

Due to the limitations mentioned above, developers want to share the code on the IOS platform, the only option is to package it into a static library. A file with a header file (e.g. SDK). But this kind of packing method is not convenient, the use is also more troublesome, we still want to share the code can be like the Framework, directly thrown into the project can be used. So people came up with a variety of artifice to get Xcode to Build out the framework that IOS can use, and here and here, this approach produces the framework of the "pseudo" (Fake) framework and the "real" (real) Framewo RK the difference.

iOS 8/xcode 6, the iOS platform adds support for dynamic libraries, and Xcode 6 natively comes with Framework support (both dynamic and static), and the above mentioned artifice is not necessary (see here for a new approach). Why IOS 8 to add support for dynamic libraries? The only reason is probably the advent of Extension. Extension and apps are two separate executables and need to share code, in which case support for dynamic libraries is essential. But the dynamic Framework and the uikit.framework of the system are still very different. The framework of the system does not need to be copied to the target program, we make the framework even dynamic, and finally to be copied into the app (app and Extension Bundle is shared), so Apple again called this framework E Mbedded Framework.

In iOS development, adding a new. Framework to the project is divided into the following three scenarios:

1. Direct referencing of the system-provided. Framework

1) Select the project name

2) Select targets

3) Check Build phases

4) added in link Binary with libraries.

5) Click on the "+" sign to add the required system-supplied. Framework File

2. References provided by third parties. Framework

1) Download the required third party provided by the. Framework

2) Copy the third-party. framework files to the folder in which the project is located

3) Select the project name

4) Select targets

5) Check Build phases

6) Add in link Binary with libraries

Ps:

If you need to introduce a. framework file that supports Cocoapods, then the cocoapods approach is the simplest.

3. Import by Cocoapods. Framework

1) in the Podfile file, write the name of the. framework file you want to import, such as pod ' XXXXXX '

2) Perform pod installation command: Pod install

Let's talk about the use of the framework file.

In the place where you need to use the. Framework, call:#import "XXXXXX.h", where XXXXXX is the name of a class provided in the. Framework and the name of the class you need to use

Reprint Please specify source: http://www.cnblogs.com/JuneWang/p/4860987.html

In iOS development, add a new. Framework to your project

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.