1.重构项目的原因
1.1公司的项目比较多,之前最多开发的时候有14个,因为公司的之前开发的项目的架构不和要求,因为这些项目大体很相似,开发一个相同的功能,要迁移很多遍,开发量很大。项目,里有不少地方不适合做迁移,为了减少开发量,我个人决定做项目重构,可以提高自己的个人能力,减少工作量

1.2采用方式:父工程嵌套子工程的方式。因为项目本身相似度还是比较高,每个需求又存在细微的差别,但是需求不是很独立,功能中图片和风格都依赖App。彼此之间依赖性比较强。个人感觉没有必要使用pod做模块化,使用静态库或者动态库就可以
2.项目改名:我们copy 一份功能最齐全的项目,把改一下名字
首先copy一份功能比较齐全的项目,进行改名:

改名字是一件麻烦的事情
比如我们现在想把 zhongxiangbao 改为 FZAllAppsProject
注意:重命名项目时,记得先备份好一份
注意:重命名项目时,记得先备份好一份
注意:重命名项目时,记得先备份好一份
未修改之前的效果

2.1、打开项目,对项目名进行 Rename,
操作:点击项目名,直接回车即可

输入FZAllAppsProject,然后回车,出现如下图:点击Rename

2.2.修改文件夹名字
原来的文件夹,都是zhongxiangbao,如图:

把zhongxiangbao 替换成 FZAllAppsProject,修改完成,如图:

2.3.修改工程文件
2.3.1 选中 FZAllAppsProject.xcodeproj 右键打开 --> 显示包内容 --> 双击打开 project.pbxproj 。
注意:打开的是 FZAllAppsProject.xcodeproj 文件,而不是 FZAllAppsProject.xcworkspace文件。


2.3.2 全部替换project.pbxproj 中zhongxiangbao为FZAllAppsProject
==操作步骤==
command +F 查找 zhongxiangbao ,然后点击replace 全部替换成为FZAllAppsProject,最后Command + s 保存一下
++注意一定要保存++
++注意一定要保存++
++注意一定要保存++
截图如下:


2.4 pod 的修改,打开Podfile 文件把里边的zhongxiangbao 替换为FZAllAppsProject ,


执行pod install

完成以后项目可以跑起来了,但是target 的名字不对
2.5.修改target 的名字,



2.6.全局替换zhongxiangbao为FZAllAppsProject

改名完成
3.新建另一个项目的target
3.1.复制一target


3.2.修改target名称



3.3修改plist文件,改为xiaoer-Enterprise

关闭项目,重新打开会发现 如下图;点击choose file


4.新建子项目工程
4.1.新建子工程文件夹FZAppSubProject

4.2.新建子工程(其实是一个.framwork的静态库),如下1,2:

选择FrameWork,下一步

4.3项目名字,然后下一步

4.4选择刚才的FZAppSubProject路径,然后下一步

4.5 将静态包的工程,导入FZAllAppsProject 工程中
右击FZAppSubProject,选择add files

选择刚刚创建的子工程的工程文件,xiaoer_pack.xcodeprog ,
注意:勾选对应的target

创建完成

5.子工程资源配置
5.1 处理plist文件
5.1.1建立如下的目录结构

5.1.2.迁移plist 文件以后,重新关闭,打开项目,项目提示plist文件丢失:

5.1.3重新选择一下plist 文件

5.2. 配置工程对应assest 盒子
5.1.新建盒子



5.2.在asset 盒子中添加图片icon和launch image


配置上自己的图片即可,lunch image不要配置路径,但是icon 需要配置路径
5.3工程配置icon
5.3.1取消小二项目默认的asset

5.3.2 配置新的asset 盒子

5.4 迁移图片到新项目盒子里


5.5 跟换证书和bundleId


6.工程文件的头文件配置
工程文件中很多头文件配置需要共同引用

7.项目整理和配置
7.1.配置项目信息

info 中信息要copy 过来

7.2.主工程找不到子工程头文件的问题

7. 3.主工程 找不到.m 文件Undefined symbol: OBJC_CLASS$_FZjingtaiTestView

解决办法:

7.4.子工程找不到主工程定义的文件
解决办法:
7.4.1.增加pch


7.4.2.增加子工程的header 搜索路径$(SRCROOT)/login_xiaoer-prefix.pch

7.4.3.增加子工程的framework 搜索路径

7. 5 主工程增加对子工程的库的依赖

7.6 子工程中加入Xib 资源;Xib 资源不能直接放入包中,否者无法访问。要放入bundle 中,然后copy 到主工程。
7.6.1 新建一个mac os 的bundle


7.6.2 设置bundle 为iOS

7.6.3 设置bundle 为bundle

7.6.4 设置hidp 为NO,为YES 时,会把图片转换为tiff 格式

7.6.5 设置bitCode 为NO

7.6.5 设置Build Active Architecture Only 为NO

7.6.6 设置子工程对bundle 的依赖,编译子工程的时候,bundle 会自动编译

7. 6.7 把xib等资源导入bundle 中

7. 6.8 主工程中copy bundle资源

7.7 把资源copy 到FrameWork中,把包设置为Embed& sign,不然frameWork 是不能放资源的

8. 修改Xib 加载图片路径的问题
详细请见另一篇简书文章
简书链接:https://www.jianshu.com/p/843f92746856
网友评论