IOS development – encapsulated static library (.A file)

Abstract

The steps of encapsulating static libraries in IOS.

IOS import external files, one is to import the source code, one is the introduction of static libraries, there are a lot of third party libraries are provided in the form of static library to us, how to make a static library?

First, when xCode creates a file, choose to create a static library file: cacoaTouchStaticLibrary

IOS development - encapsulated static library (.A file)

After the completion of the creation, we write our method and implementation in it:.H file and.M file #[email protected] MyStaticLibrary: NSObject

– (void) myLog;

@end

#import “MyStaticLibrary.h”

@implementation MyStaticLibrary

– (void) myLog{

NSLog (@ myLog);

}

@end

Two, generate static library files:

It is necessary to select the device into IOS Device

IOS development - encapsulated static library (.A file)

Then use command+B to compile if the Xcode reports such an error:

IOS development - encapsulated static library (.A file)

We need in Peoject-> Code Signing -> Code Signing Identity into IOS Developer

IOS development - encapsulated static library (.A file)

Compile again. Then you will see that the.A file in Products is programmed by red. We right show in finder, you can see the successful compilation of static library files.

Three, merge static library

In the folder, we see there are two.A files, are used in the simulator debugging and device debugging, if we need to switch the machine simulator does not stop in the development, we can be the two merged into a static library file:

In the end use: lipo -create -output command:

IOS development - encapsulated static library (.A file)

At this time, our static library files do.

Four, the use of static library files:

The.A and.H files into the project, the need to import the header file, you can use.