XCODE6 supports the creation of dynamic libraries in Xcode, and the process is simple.
To create a new project, select the framework:
After that we write our code in, for example we create a MyObject class:
@interface MyObject : NSObject-(void)myLog;@end@implementation MyObject-(void)myLog{ NSLog(@"framework");}@end
Similar to the static library, if we do not do any processing, the package of library files can only be used in the simulator or only on the real machine, in order to facilitate our debugging, we can add a script command, yes, build a framework that supports both the simulator and the real machine:
New target:
Select aggregate:
After that, we click the plus sign in Target's build phases:
Add a run Script:
Add the following script to the inside:
# Sets the target folders and the final framework product.
# if the project name and the Framework's Target name are different, customize the fmkname
# Example : fmk_name = "Myframework"
Fmk_name=${project_name}
# Install Dir'll is the final output to the framework.
# The following line create it at the root folder of the current project.
Install_dir=${srcroot}/products/${fmk_name}.framework
# working dir would be a deleted after the framework creation.
Wrk_dir=build
Device_dir=${wrk_dir}/release-iphoneos/${fmk_name}.framework
Simulator_dir=${wrk_dir}/release-iphonesimulator/${fmk_name}.framework
#-configuration ${configuration}
# Clean and Building both architectures.
Xcodebuild-configuration "Release" -target "${fmk_name}" -sdk iphoneos Clean build
Xcodebuild-configuration "Release" -target "${fmk_name}" -sdk iphonesimulator Clean build
# cleaning the oldest.
If [-D "${install_dir}" ]
Then
RM-RF "${install_dir}"
Fi
Mkdir-p "${install_dir}"
Cp-r "${device_dir}/" " ${install_dir}/"
# Uses The Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
Lipo-create "${device_dir}/${fmk_name}" " ${simulator_dir}/${fmk_name}" -output "${install_dir} /${fmk_name} "
Rm-r "${wrk_dir}"
Open "${install_dir}"
Next, we need to expose the interface file to the outside world and move it to public:
After we run the program, it is important to note that if you want to support 64-bit, you need to set in the compilation options, as follows:
At this point, our framework library file is finished, select our project in Xcode window->projects, click the small arrow to enter the folder:
We can find our framework file in Build->product and we can use it when we assign it.
Let's test it, create a new project, import the static library just made, such as the next header file, call method, can be used.
#import <MyFramework/MyObject.h> MyObject * obj = [[MyObject alloc]init]; [obj myLog];
Two tips:
First, if you run a program similar to Reason:image not found! crash information, the possible reason is that some files in the dynamic library file your project has been included in the build phases to change the required to optional.
Second an excellent and complete framework may contain quite a few files, including the framework of its own and other third parties, for ease of use, we can import header files into one header file, here is a place where we need to be aware that the header files that we add directly to the framework project are not compiled, My solution is to solve the problem by building an OC class that imports the total header file in this class and hides the class as private.
Creating a reusable frame framework in iOS