Development may have some of their own classes and tool functions, when the code is reused repeatedly. The simplest way to reuse code is to simply copy/paste. However, when you fix a bug or upgrade, you will encounter the need to modify all copies. At this time the static library will save the bitter force of us.
A static library is a wrapper for several classes, functions, definitions, and resources
Can be shared between projects after they are packaged
The following is a brief excerpt from: http://www.it165.net/pro/html/201404/11585.html
Program compilation generally requires preprocessing, compiling, compiling, and linking several steps. For some common code in the project, if you want to reuse it, you can compile the code into a static library file. In the link step, the linker obtains the corresponding code from the library file and generates the executable file. The execution file of the static library contains the complete code in the library, but multiple uses result in multiple copies of redundancy. The difference between a static library and a dynamic library is that the static library is duplicated during the link phase, regardless of the run phase of the program, and dynamic libraries are dynamically loaded into memory by the system when the program is run for program invocation, which can save memory significantly.
There are several reasons why you might create a static library:? 1. You want to package and easily share some of the classes that you and your colleagues in your team use frequently with others around you. 2. You want to have some generic code under your control so that it can be repaired and upgraded. 3. You want to share the library with others, But don't want them to see your source code.
~~~~~~~~~~~~~~~~~~ Gorgeous split-line ~~~~~~~~~~~~~~~~~~~~~~~
Let's create a static library.
Open Xcode click framework&library= "Cocoa Touch static Library
The sample code is as follows:
MyfirstLib.h file:
#import <Foundation/Foundation.h> @interface myfirstlib:nsobject-(void) logmyfirstlib; @end
MYFIRSTLIB.M file:
#import "MyfirstLib.h" @implementation myfirstlib-(void) logmyfirstlib{NSLog (@ "This is my fitst static Lib");} @end
2. After the command+b compilation, the LINMYFIRSTLIB.A file below the products directory has red to black.
3. Click on the show in finder to locate the. a file
4. The. h files in a file and include folder are shown below.
5. Create a new project pour. H and. A into the project
6. Click Add other in the Finder to find. A and. H file
Example code:
#import <UIKit/UIKit.h> #import "MyfirstLib.h" @interface viewcontroller:uiviewcontroller@end@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Myfirstlib *myfirstlib = [[Myfirstlib alloc] init]; [Myfirstlib Logmyfirstlib]; } @end
7. Print the results as follows:
8. All that's left is to share.
iOS practice-xcode6 Creating a static library