什么是库
库是程序代码的集合,是共享程序代码的一种方式
根据源代码的公开情况,库可以分为2种类型
开源库
公开源代码,能看到具体实现,比如SEWebImage, AFNetworking
闭源库
不公开源代码,是经过编译后的二进制文件,看不到具体实现
主要分为:静态库,动态库
静态库和动态库

制作.a文件
step 1

step 2
将要打包的代码copy到工程中,资源文件不能放进去
step 3
选择要暴露在外的头文件,如下图,然后选择copy headers project下的+号,添加头文件

step 4
选择真机,build ⚠️真机build的库只能用在真机上,模拟器build只能用在模拟器上
*** 如果有可以给外部看的文件,将其移动到public处即可

step 5 如果想该库既能用在真机上又能用在模拟器上,可以将其合并

step 6 创建工程测试库
如果报错,需要在设置中添加other links flg
创建.framwork文件
step 1

step 2

step 3

step 4
将写好的源码连同.bundle文件一起拷贝到framework工程中


step 5
将需要公开的头文件拖到public下面

step 6
分别选择模拟器和真机build之后合并

⚠️⚠️⚠️手工制作.framework文件太麻烦,容易出错,可以借助模版,地址:https://github.com/kstenerud/iOS-Universal-Framework
下载到本地后,执行命令,如下

然后在xcode中创建工程

制作静态库的注意点



网友评论