IOS static library Compilation

Source: Internet
Author: User

When using third-party sdks, you can often compile your classes into static libraries. you can hide your private information, such as private APIs and apikey, when provided to developers;


Compile the open-source jsonkit class library into a static library, and then use the compiled static library to parse a JSON file.


1. Create a static library project, select framework & library -- next, and name it jsonkitlib.

2. Delete automatically generated jsonkitlib. h and jsonkitlib. H (because they are packed with other people's classes, you do not need to delete these two files if you create them yourself;


3. note that the IOS simulator is based on the X86 architecture of the Mac OS platform and the ARM architecture is applied to iOS devices. Therefore, the static library provided to them must also be applied to their architecture, fortunately, xcode can compile the libraries of these two architectures at the same time;

During compilation, it is adjusted to iOS device, product --> build. If it is adjusted to others, it cannot compile static libraries.


4. after compilation is successful, libjsonkitlib will be released. a. Right-click and select Show in finder. There will be a static library under the debug-iphoneos and debug-iphonesimulator folders. Let's take a look at the file type with lipo.

One is the ARM architecture and the other is the i386 architecture of the X86 platform. If we want to run the test on the simulator, We need to copy the static library under debug-iphonesimulator, if you need to test a real machine or a real machine, it must be a static library under debug-iphoneos;


5. now we can test the compiled static library. It is best to copy both libraries for easy addition and use. Create an xcode project and run jsonkit. add the H file to the new project, and then add the static library compiled under debug-iphonesimulator.


6. The test code here uses the National Meteorological Administration API and the JSON file is returned.

-(Ibaction) tapjsonpaser :( ID) sender {nserror * error; nsurlrequest * request = [nsurlrequest requestwithurl: [nsurl urlwithstring: @ "http://m.weather.com.cn/data/101180701.html"]; nsdata * repsponse = [nsurlconnection failed: request failed: Nil error: & error]; jsondecoder * jsonpaser = [[jsondecoder alloc] init]; nsdictionary * weatherdic = [jsonpaser objectwithdata: repsponse error: & error]; nslog (@ "Resolution result: % @", weatherdic); [jsonpaser release];}

Result

However, some people may think it is too troublesome to pack these two static libraries into a static library and use commands.

Lipo-create debug-iphoneos/libjsonkitlib. A debug-iphonesimulator/libjsonkitlib. A-output libjsonkittestlib.



Although the method is good, it will sacrifice space and the file will become larger. The jsonkit source file is 12kb + 177kb, and after being compiled into a static library, the ARM architecture's ipvkb i386 architecture is 263kb, package them into a static database of kb;



Related Article

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.