1.主工程是:YYTDemo 平级的子工程是:YYTLIb
2.主工程引用子工程
3.新建 一个workspace之后新建Framework(YYTLib)

新建完成之后如下图:

4.接下来新建一个主工程(YYTDemo)(Add to 和 Gruop 的时候要选择你新建的那个WorkSpace哦)
Framework与主工程新建完成以后如下图:

5.之后呢我们要开始联编了
(1)YYTDemo------->"Targets"------->"Build Phases"--------->"Link Binary With Libraries" 加入YYTLib.framework
(2)YYTDemo------->"Targets"------->"Build Settings"--------->"Header Search Paths"添加“$(SRCROOT)/../YYTLib”
(3)点击工程选择运行平台----->"Edit schem"-----左侧的功能列表------->"Build"【1.将上面的"Build Options选项的2个多选框勾去掉" 2.添加YYTLib.framework,并且要将他移到主工程上面 3.将下方shared选项框勾选上】如下图:

(4)(2)YYTDemo------->"Targets"------->"Build Settings"--------->"Base SDK"改为“Latest iOS”
=(5)编译通过(模拟器没问题,但是真机的话可能会报错bitcode,把build Settings里面的bitcode改为NO就可以了)
(6)主工程可以引用YYTLib.framework了
接下来说一下如何引用YYTLib.framework里的公开类,我新建了一个YYTLibManager.h,并且添加了一个方法:

(1)YYTLib------->"Targets"------->"Build Phases"--------->"Headers" 加入YYTLibManager.h
(2)然后在YYTLib.h里引入公开的.h文件

(4)主工程可以直接引用此getImage方法

多工程中的子工程里面有时候会用到图片啊、plist文件的 ,子工程使用[NSBundle mainbundle]方法时会找不到该资源文件 ,这时候我们只需要一个bundle就可以解决找不到的问题,接下来跟着我做:



注意上面红圈的地方,一定要选择你相应的子工程

上图资源文件已经创建好,现在将一张图片放入资源文件内


还需要将bundle放入YYTLib.framework的“Target”的“Target Dependencies”
最后一步,需要在主工程中添加一段脚本代码

cp -R ${BUILT_PRODUCTS_DIR}/YYTLibResource.bundle ${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app,只需要把YYTLibResource.Bundle换成自己的即可
上面代码已经给出,可能 正常用了
网友评论