今天看到群里面又说在说静态库,我看了也手痒痒想自己试试怎么制作的,其实所谓静态库就是把.m给封装起来不让别人看到你是怎么实现的,然后把.h文件暴露出来, 让使用者调用的,通俗点就是我们平时使用的那个只有头文件的 SDK(百度,高德API,支付宝,微信 API 等)
话不多说,下面开始


第二步:
在StaticText.h 申明方法并在. m 文件中实现

第三步, 配置下工程


此时在编译下(command+B) StaticText.a 就会变黑了 如图


第四步 选择 Edit Scheme 选择 Release 在编译下(command+B)


之后 (这里特别注意一点)需要选择真机和模拟器 分别编译下(command+B)
第五步 我们需要选中 libStaticText.a 然后 Show in finder 可以在 finder 下面看到下面3中(其实应该有4中还有一张真机下的 Debug) 因为 Debug 我们只是测试用的所以我们就需要Release 下面的真机和模拟器就可以了
之后在新建个文件夹把Release-iphoneos 和Release-iphonesimulator 装起来

第六步 打开终端把Release-iphoneos 和Release-iphonesimulator 里面的. a 文件合并成一个文件
lipo -create /Users/wangyu/Desktop/text/Release-iphoneos/libStaticText.a /Users/wangyu/Desktop/text/Release-iphonesimulator/libStaticText.a -output /Users/wangyu/Desktop/text/libStaticText.a
格式: lipo -create 真机下的.a路径(空格) 模拟器下的.a路径(空格) -output (空格) 合成后的路径及名称
注意 :空格很重要
就这样之前文件夹下面就会多一个. a 文件




第八步 需要导入头文件 然后在调用之前的方法能打印出你之前写的就说明成功了("测试静态庫")
#import "StaticText.h"
StaticText *text = [[StaticText alloc]init];
[text sayHello];

在前面还写了有关静态库静态库FrameWork文件制作方法
网友评论