Chinaunix首页 | 论坛 | 博客
  • 博客访问: 463779
  • 博文数量: 145
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1060
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-22 11:52
个人简介

专注计算机技术: Linux Android 云计算 虚拟化 网络

文章分类

全部博文(145)

文章存档

2016年(3)

2015年(21)

2014年(75)

2013年(46)

我的朋友

分类: iOS平台

2014-10-19 10:01:10

 Tutorial for Creating Universal Static Lib,

 In this tutorial we are creating Static Library for Logger class.

Step 1 : Create a New Project, Named it "Logger"

Step 2 : Create Classes

You can create as many classes you wants, In our tutorial we will create one class named "Logger". 
So, now two files should be in our resource.
1. Logger.h
2. Logger.m

Step 3 : Put some useful code into Classes


点击(此处)折叠或打开

  1. // Logger.h
  2. #import <Foundation/Foundation.h>

  3. @interface Logger : NSObject

  4. +(void)log:(NSString *)sLogStr;

  5. @end

  6. // Logger.m

  7. #import "Logger.h"

  8. @implementation Logger

  9. +(void)log:(NSString *)sLogStr{

  10.         NSLog(@"%@",sLogStr);


  11. }

  12. @end







Step 4 : Create New Target

Create New Target from File Menu.


New Target
New Target
Select Cocoa Touch Static Library


Select Cocoa Touch Static Lib
Select Cocoa Touch Static Lib
Step 5 : Add files to Compile Resource

 
  • Select "Logger" Target of Static Library
  • Go to Build Phases
  • In Complied Sources section, Add all the .m and .mm files.
  • In Copy Files section, Add all the .h files and resource files.

Build Phases

Step 6 : Compile Project with Static Library Target


  • Compile Project for iOS Device
  • Compile Project for Simulator
You can find two different .a files generated in build foders.

Find .a file
Find .a file

Step 7: Make Static Library Universal 

You can find two different library now, one is for simulator and one is for iOs devices.

  • Create a New Folder and name it LoggerMerge.
  • Copy libLogger.a file of Debug-iphoneos folder to "LoggerMerge" rename it to libLogger_device.a
  • Copy libLogger.a file of Debug-iphonesimulator folder to "LoggerMerge" rename it to libLogger_simulator.a
  • Open LoggerMerge folder with Terminal
  • Fire below command
lipo -create "libLogger_simulator.a" "libLogger_device.a" -output "libLogger.a"

Now, you can find libLogger.a in LoggerMerge folder, this is Universal static library file.
Now, Just one thing you need is headers, See above screenshot there is folder called include in both build folder. Just copy header file from this folder.

Step 8 : Test Static Library

  • Create New Project, name it TestLogger
  • Import libLogger.a and header files
  • Import header file "Logger.h" anywhere you want to use
  • Now, Use this Logger class as default practice.
  • In our case, [Logger log:@"Test String"];
  • Run Project in Simulator and Device both
Thats's it!! You have your own static Library!!

Thanks for Reading the Article !!

Follow me @

Contact Us @

From: http://jaym2503.blogspot.in/2013/01/how-to-make-universal-static-library.html
阅读(1259) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~