Use of the iOS Static library (libarary)

Source: Internet
Author: User

(The account has been found, migrated back from the new blog)

Static libraries: A mechanism for sharing the same code in multiple application.

Build a single Viewcontroller project, and then right-build the new NewFile in the left sidebar->framwork&libarary->staticlibaray


The results of the completion are as follows:

Select Staticlibaray,cmd + B build, then the LIBSTATICLINARAY.A in the products will turn black, indicating that the compilation was successful.


Switch to project, add Libaray


The imported #import "StaticLibaray.h" still displays file not Found. This is because Iosstaticlibaray now has no StaticLibaray.h to search for. We need to set the header file search path for project.




Now you need to know the path to the static library, select Libstaticlibaray-> Show in Finder

This is the path of the point staticlibarary, we just add these to hears Search path, on different Macs this path is certainly not the same, so we need to use a few of the system's macros.

+ $ (built_products_dir)

Build/products/debug-iphoneos

Build after successful, the final product path--can be Build Settings of the parameter per-configuration Build Products Path set in the item


+ $ (target_name)

Target Project Name


+ $ (srcroot)

engineering documents (e.g. nuno.xcodeproj ) of the path


+ $ (current_project_version)


+ $ (inherited)


+ $ (build_dir) "/users/username/library/developer/xcode/deriveddata/project-dxdgjvgsvvbhow Gjqouevhmvgxgf/archiveintermediates/project Distribution/buildproductspath "


+ $ (build_root) "/users/username/library/developer/xcode/deriveddata/project-dxdgjvgsvvbhow Gjqouevhmvgxgf/archiveintermediates/project Distribution/buildproductspath "

+ $ (build_variants) Normal


+ $ (build_dir) "/users/username/library/developer/xcode/deriveddata/project-dxdgjvgsvvbhow Gjqouevhmvgxgf/archiveintermediates/project Distribution/buildproductspath "


+ $ (build_root) "/users/username/library/developer/xcode/deriveddata/project-dxdgjvgsvvbhow Gjqouevhmvgxgf/archiveintermediates/project Distribution/buildproductspath "

+ $ (build_variants) Normal


+ $ (effective_platform_name) ' Iphoneos ' or ' iphonesimulator


We now add $ (built_products_dir)/include/staticlibaray to the head Search Path debug, run no problem. Debug mode I believe has been resolved, the following see release mode

Now cut back to staticlibarary,product->archive.

And then to project, Product->archive found and not found file, because we haven't set the release path yet, so let's go find the path to the release.

/users/barryclass/library/developer/xcode/deriveddata/iosstaticlibarydemo-hitdffgifzihnjehziiwfvgvagxy/build/ Intermediates/archiveintermediates/staticlibaray/buildproductspath/release-iphoneos/include/staticlibaray


Refer to the above macro, we can write

$ (build_root)/release-{effective_platform_name}/include/staticlibaray/

We now add in Head Search Path release$ (built_products_dir)/include/staticlibaray, Archive no problem. G Fix it.

All of our settings are set in Project project, not in a single target, but can be set directly in target.


When set in Project, we add $ (inherited) to the corresponding item in target, which represents the inheritance of the settings in project.


If we create a new class in Staticlibaray, and then add the new. h file to the build phases, Copy files in Staticlibaray, then you can compile it and use it in project. But there is a new problem, as long as the static library changes we have to build a static library, so that the changes to take effect. If we make the static library a dependency on project, we don't have to manually build the static library, and build it automatically each time we build project.

Select Iosstaticlibararydemo, select Target---build phases, target Dependencies Click on the plus sign below to find that there is no static library we want to add. Don't worry, we just have to drag Staticlibaray into the Iosstaticlibarydemo.


This is then click the plus sign to add


Get!


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of the iOS Static library (libarary)

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.