IOS adds a static library above Xcode 4.x

Source: Internet
Author: User

Reference website: http://my.oschina.net/edwardlau/blog/95924

Common code can be extracted from the static library as a public class method, easy to call elsewhere, generally we have to prepare 2 sets of static library, one is used on the simulator, a set is used by the real machine,

To create a static library:

Create a new project in Xcode. Select as:

Then click Next and the next step is to fill in the stuff at random.

After creating the complete structure such as:

The static libraries that are not generated are red under products,

Then write a simple method in the. h file SayHello;

The code is as follows:

?
1234567 #import <Foundation/Foundation.h>@interface TestStaticeLibrary : NSObject-(void)sayHello;@end

. m file Contents:

?
12345678 #import "TestStaticeLibrary.h"@implementation TestStaticeLibrary-(void)sayHello{    NSLog(@"Hello OSChina");}@end

When you are finished, click Schema as

Click: Select Edit Schema, such as:

If you determine the version is not much of a problem, the builder Configuration in the debug mode to release.

Choose to build the corresponding platform

Since the simulator is developed in i386 mode, you need to change your iOS device to iphone 6.0 Simulator if you want to use a static library in the simulator. Then click Run,

Then click Select Project to find the corresponding item, as

Click the small arrow will jump to the specified folder, and then select Build-->products will see a debug-iphonesimulator folder, when the corresponding file has been generated

Call the Static library:

Create any iOS project and drag the static library you just generated into the new project, with the following structure:

If it is not enough to simply add a static library, there is a folder included in the previous build, with an. h file in it, and an. h file in the project with the final directory structure as follows:

If you are not directly dragged into the project, the right mouse button in the project, select Add Files to "XXXX"

In Viewcontroller, the following code is typed:

?
123456789101112131415161718192021222324252627 #import "ViewController.h"#import "TestStaticeLibrary.h"@interface ViewController () @end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];        TestStaticeLibrary *t = [[TestStaticeLibrary alloc] init];    [t sayHello];         // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

Then run the project to see the following in the console

This completes a static library call to iOS.

PS: After the introduction of the project remember to check if the static library exists summary below:

If found not, press + to add the static library

IOS adds a static library above Xcode 4.x

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.