Overview
In the process of project development, static library files are often used. For example, the exchange of business between two companies, it is impossible to send the source code to another company, when the private content into a static library, others can only invoke the interface, but not know the details of the implementation.
A library is a collection of program code that does not have a main function. In addition to the static library, there are dynamic link libraries, the difference between them is: the static library can be compiled into our execution code, the application can run in an environment without a static library, the dynamic library can not be compiled into our execution code, the application must be in the context of a linked library file run. In addition, the dynamic library in the AppStore, it is likely to be rejected, not on the shelves.
Thus, in general, we are using the. a static library.
Create a static library
1, create the static library, new->project, select the static library,
2. Click Next to name the static library project Timedate, which is used to process the time and date
After you have created a static library for your project, Xcode automatically creates a timedate.h/.m file for us, as shown in
3. Add function Code
TimeDate.h
#import <Foundation/Foundation.h>@interface timedate:nsobject-(NSString *) Changetostandardtime: (nstimeinterval) timeinterval; @end
Timedate.m
#import " @implementation Span style= "color: #000000;" > Timedate -(nsstring *) Changetostandardtime: (nstimeinterval) timeinterval{ NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init]; [Dateformatter Setdateformat: @ " yyyy-mm-dd HH:mm:ss " *time = [Dateformatter stringfromdate:[nsdate Datewithtimeintervalsince1970:timeinterval]]; return time;} @end
4, compile the project, respectively, for the simulator compilation and the real machine compile, generate the corresponding static library. A file
Libtimedate.a->show in Finder view generated static. A Files
5, all the. h header files are publicly packaged
In the folder, you can see LIBTIMEDATE.A and TimeDate.h.
The static library has been packaged
Call implementation
Create a new project to pull Libtimedate.a and TimeDate.h into the project, respectively.
Call is simple
1. Reference:#import "TimeDate.h"
2. Call directly
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *)event{ NSLog ( @ "changetostandardtime---%@", [[[[Timedate Alloc]init] Changetostandardtime: 1444793824]);}
Other resource packaging
In some static libraries, pictures and xib files are used, which we also need to pack together.
1. Packaging pictures
Create a new folder, named and Static library consistent, such as timedate.bundle, display the contents of the package, the picture can be pulled in.
In the static library to use the picture, you should pay attention to the path, the general use is as follows:
+ (UIImage *) loadimage{ *image=[[nsbundle mainbundle] Pathforresource:@ "ceshi.png " oftype:nil indirectory:@"timedate.bundle"]; return [UIImage imagewithcontentsoffile:image];}
Of course, this part can be written as a macro
At last
We give each other's, contain
IOS Component Components-Create a static library