我们在iOS开发中,难免会遇到项目做到一半要改名字的情况。如果项目名差的太大,工程名看起来总是不舒服的,就会想着为工程改个贴切的名字,那么你就为用到本文记录的内容。
下面我就拿一个中等大小的项目来实际操作一下,并记录整个要修改的地方。
该项目的结构如下:
![](http://upload-images.jianshu.io/upload_images/727768-ae8a76293231eb2a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
项目中还用到了几个第三方框架:
![](http://upload-images.jianshu.io/upload_images/727768-806533cc0fca56b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
接下来,就要开始修改项目名称了。假设我要把doutu
改为shopping
。
提醒:
- 在改工程名之前,要注意三件事:一定要备份,一定要备份,一定要备份。
直接修改的。
![](http://upload-images.jianshu.io/upload_images/727768-bdce405283969a1d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
选中project 单击project名字 或者 选中project+回车。
![](http://upload-images.jianshu.io/upload_images/727768-6a35f5bc9bcae7e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
修改project的名称之后,回车会有提示:
![](http://upload-images.jianshu.io/upload_images/727768-73d9ca12a63eb159.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里点击Rename,将project中部分doutu
改为shopping
。
修改之后,哪些地方有明显变化呢?
![](http://upload-images.jianshu.io/upload_images/727768-bed3cea9c0e91c44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
选中文件夹 单击文件夹名字
或者 选中文件夹 回车
。
![](http://upload-images.jianshu.io/upload_images/727768-c474084ef5373645.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
修改之后,回车是这样的:
![](http://upload-images.jianshu.io/upload_images/727768-5346b08624aebf42.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
虽然在Xcode 里文件夹的名字修改了,但是实际上文件夹里的名字还是没有修改,我们需要去真实文件夹里再修改一次。
![](http://upload-images.jianshu.io/upload_images/727768-39e1e7a7fc836b76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在上一步修改玩真实文件夹的名字后,工程中所有的类都变成了红色(文件找不到)。如下图所示:
![](http://upload-images.jianshu.io/upload_images/727768-7abe3819f7b3868e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
主要是因为工程中的文件夹指引的路径不对。
![](http://upload-images.jianshu.io/upload_images/727768-ad1f174d26519276.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
按照如上步骤所示,找到我们刚才修改的真实shopping
文件夹,点击Chose 即可。
这时候,因为文件夹关联的真实文件夹路径正确了,所有红色的文件都正常了。
这是修改后的样子:
![](http://upload-images.jianshu.io/upload_images/727768-e548535f3ef6b632.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
全局搜索doutu
,搜索结果如下:
![](http://upload-images.jianshu.io/upload_images/727768-1169a39b2e69d848.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
接下来是将doutu
替换为shopping
。
![](http://upload-images.jianshu.io/upload_images/727768-6ea059a98619b0d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
点击Replace All之后,大部分doutu
都会被替换为shopping
,但是还是有一些顽固的残留。
![](http://upload-images.jianshu.io/upload_images/727768-cfc5f12c7d96a719.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
可以看出,这个是project 文件中,我的第三方框架的framework Search Paths 和Library Search Paths 的路径错误。即:
![](http://upload-images.jianshu.io/upload_images/727768-b106ab622282be4a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里只需要将doutu
修改为 shopping
即可。
怎么修改呢?
有两种方式,第一种双击framework Search Paths
和Library Search Paths
后面的值,然后单独修改每个值。
![](http://upload-images.jianshu.io/upload_images/727768-c9612de19369c44e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
第二种方案,先将framework Search Paths
和Library Search Paths
中的值都删掉,然后把第三方删除,再重新添加。
![](http://upload-images.jianshu.io/upload_images/727768-39584d21378211b1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里点击Remove References删除,然后再把Vendor文件夹添加进工程即可。
如果你的工程里添加了pch文件,因为修改了文件夹,project名字,所以pch文件夹路径也要修改。修改前编译运行,会报如下错误:
![](http://upload-images.jianshu.io/upload_images/727768-ea27ac5994889483.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在Build Settings 中搜索Prefix,修改Prefix Header 的值。
![](http://upload-images.jianshu.io/upload_images/727768-5908567d792c780e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
上面把doutu/shopping-Prefix.pch
修改为shopping/shopping-Prefix.pch
即可。
此时再次编译运行,依然会有一个错误,错误如下:
![](http://upload-images.jianshu.io/upload_images/727768-741304ae24963d11.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后依然去 Build Setting
中搜索info.plist。
![](http://upload-images.jianshu.io/upload_images/727768-0d76da42c7ccdf5a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
上面将doutu/Info.plist
修改为shopping/Info.plist
即可。
到这里,工程应该已经可以正常运行了。
![](http://upload-images.jianshu.io/upload_images/727768-82b83079135c73fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
但是,如果你想追求完美,依然还有两个地方需要修改。
要修改的其实是这个地方的显示名称:
![](http://upload-images.jianshu.io/upload_images/727768-50d2e235731c95e1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
怎么修改呢?
点击scheme值,然后选择 Manage Schemes...
![](http://upload-images.jianshu.io/upload_images/727768-87d238674a77346f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
接下来会进入到一个弹出窗口,选中一行,点击scheme值
或者 回车
:
![](http://upload-images.jianshu.io/upload_images/727768-9703d4c38fc061c3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里把doutu
修改为 shopping
就会看到 scheme 变成了shopping,如下图所示:
![](http://upload-images.jianshu.io/upload_images/727768-21c177f9ce612645.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)