Comprehensive understanding of IOS static Library development
Brief introduction
In enterprise development, some core technology or common framework, for security and stability considerations, do not want to be known to the outside world, so the core code will be packaged into a static library, exposing only the header files to the programmer (such as: friends, Baidu Maps and other third-party SDK)
The existence form of static library and dynamic library
The difference between a static library and a dynamic library
Static libraries: When linked, the static library is completely copied to the executable file, and multiple copies are used multiple times.
Dynamic Library: Link is not copied, the program is dynamically loaded into memory by the system, for program calls, the system is loaded only once, multiple programs are shared, saving memory
Note: If you use a dynamic library in your project, Apple will reject
Version of the static library file (4 types)
Real Machine-debug version
Real Machine-release version
Simulator-debug Version
Simulator-release Version
Debug (Debug) version
Complete symbolic information for easy commissioning
No optimizations are made to the code
Release (release) version
Does not contain the complete symbolic information
The execution code is optimized.
is slightly smaller than the debug version
The release version will be faster in terms of execution speed (but does not mean a significant increase)
So we are generally in the development of packaging release (release) version, to provide external
Introduction to the CPU architecture of the device (supplemental knowledge)
Simulator:
4s~5:i386
5s~6plus:x86_64
Real machine:
Make a static library-debug version
1. New Project
2. Add a static library and name it
3. The code that needs to be packaged into a static library is placed within this folder
4. Recreate the test class (Hscalculate) to provide a method for calculating two numbers in the outside world
HSCalculate.h
@interface hscalculate:nsobject+ (nsinteger) SumNum1: (Nsinteger) num1 num2: (Nsinteger) num2; @end
Hscalculate.m
1 #import " HSCalculate.h " 2 @implementation hscalculate 3 + (nsinteger) SumWithNum1: (Nsinteger) num1 num2: (nsinteger) num24{5 return num1 + num2; 6 }7@end
5. Files that need to be exposed to the outside world (interface)
6. Package support emulator and the static library of the real machine (select the real machine and the simulator to run, will generate the corresponding static library)
7. View the packaged static library
Two folders, the. A file inside is a packaged static library
Use the following command to view the CPU architectures supported by the static library (see the CPU schema types described above)
Lipo-info xxx.a
View the CPU architectures supported by the static libraries of the packaged simulator and the real machine, respectively
You will find the static library of the simulator less 4s~5:i386 architecture
Reason:
The following debug:yes indicates that only the schema of the selected emulator is compiled, no is the CPU architecture supported by all emulators (debug Yes status changed to No)
When you are finished modifying, recompile:
8. In this project to debug the static library, VIEWCONTROLLER.M import HSCalculate.h, test run, you will find an error
1 #import "ViewController.h"2 #import "HSCalculate.h"3 @interfaceViewcontroller ()4 @end5 @implementationViewcontroller6- (void) Viewdidload {7 [Super Viewdidload];8Nsinteger result = [Hscalculate sumWithNum1: atNUM2: -];9NSLog (@"Result:%d", result);Ten } One @end
Error:
Reason:
Need to import a static library (compile to run successfully)
9. Also support the static library of the real machine and simulator (need to merge)
The static library of the real machine and the simulator is not the same, can not be used in both the real machine and the simulator, but to meet this requirement, the compiled two static libraries to merge
Consolidation good or bad:
Good: You can either debug on a real machine or debug on a simulator during development
Bad: If the static library is too large, the merge package will be very large, so many third-party static libraries. A is a version-sensitive
Merging to produce a new static library:
- Lipo-create debug-iphoneos/xxx.a debug-iphonesimulator/xxx.a-output xxx.a
10. Pull the merged static library and external access files into the new project and use the (inc file)
New Project test:
Make a static library-release version
The same as the debug version, but at compile time, change the following options to
Making a static Library-. Framework Edition
Step with the production. A static library, basically consistent, but note the following points:
1. Select the framework
2. Compile, the default is made into a dynamic library, to select the following
3. When merging static libraries, the Libstaticlib file in the. framework file is selected
Merge:
Delete Libstaticlib,libcalculatetool pull into Libstaticlib.framework project, libstaticlib.framework Static library production complete
iOS Development-loading technology picks & Full understanding of iOS static library development