我有一个项目叫XXX。我想把这个项目重命名为YYY。

请注意,XXX是一个非常常见的术语(例如:“数据”,或者简单的“项目”),因此一个简单的RegEx搜索和替换是不可能的,因为有破坏项目配置文件的风险。

我的当前项目目录包含以下项目:

XXX XXXTests XXX . xcodeproj

我想把它们重命名为:

年年 年 YYY.xcodeproj

... 分别与必要的变化反映在我的项目文件。

我如何才能在不手动创建和填充新项目的情况下实现这一点呢?


当前回答

One more thing to note that I don't think has been noted yet is if you are using CoreData objects along with a lazy persistentContainer in the AppDelegate file (or anywhere else), you may get an error saying NSManagedObjectContext is nil (or something along those lines). Change the name for any NSPersistentContainer to use the NEW app name. That should fix the issue! If not, according to this old SO post the solution is to delete your old .xcdatamodeld file and create a new one adding back all the entities again.

其他回答

更改项目名称;

在project导航器中选择您的项目。 在文件检查器的Identity and Type部分中,在name字段中输入一个新名称。 按Return键。 将显示一个对话框,列出项目中可以重命名的项。该对话框包括更改后项目将如何显示的预览。 若要选择性地重命名项,请禁用不想重命名的任何项的复选框。若要仅重命名应用程序,请保持应用程序已选中,并取消选择所有其他项。 按“重命名”

为卢克-韦斯特的精彩回答补充一点:

使用CocoaPods时

第二步之后:

Xcode辞职。 在主文件夹中,重命名OLD。xcworkspace到NEW.xcworkspace。

第四步之后:

In Xcode: choose and edit Podfile from the project navigator. You should see a target clause with the OLD name. Change it to NEW. Quit Xcode. In the project folder, delete the OLD.podspec file. rm -rf Pods/ Run pod install. Open Xcode. Click on your project name in the project navigator. In the main pane, switch to the Build Phases tab. Under Link Binary With Libraries, look for libPods-OLD.a and delete it. If you have an objective-c Bridging header go to Build settings and change the location of the header from OLD/OLD-Bridging-Header.h to NEW/NEW-Bridging-Header.h Clean and run.

当遵循@Luke-West + @Vaiden的解决方案时,额外说明:

如果你的方案没有改变(仍然显示我的mac)在左上角旁边的停止按钮:

点击新建项目名称(停止按钮旁边)>点击编辑方案>构建(左侧)>删除旧目标(会说它缺失),并在新命名项目标志下替换为新命名的项目

而且,我不需要使用@Vaiden的解决方案的第三步。只需要运行rm -rf Pods/ in terminal就可以去掉所有旧的pod文件

我也不必在@Vaiden的解决方案中使用第9步,相反,我只是在链接二进制库下删除了旧项目命名的框架(新命名的框架已经在那里)

所以更新后的步骤如下:

步骤1 -重命名项目

如果你在你的项目中使用cocoapods,关闭工作空间,然后打开XCode项目进行这些步骤。 在Xcode视图左侧的“项目导航器”中单击要重命名的项目。 在右边选择“文件检查器”,项目的名称应该在“身份和类型”下面,将其更改为新名称。 点击下拉菜单中的“重命名”

步骤2 -重命名方案

在顶部栏(靠近“停止”按钮),有一个旧产品的方案,点击它,然后进入“管理方案” 单击方案中的旧名称,它将成为可编辑的,更改名称 XCode辞职。 在主文件夹中,重命名OLD。xcworkspace到NEW.xcworkspace。

步骤3 -重命名文件夹与您的资产

Quit Xcode In the correctly named master folder, there is a newly named xcodeproj file with the the wrongly named OLD folder. Rename the OLD folder to your new name Reopen the project, you will see a warning: "The folder OLD does not exist", dismiss the warning In the "Project navigator" on the left, click the top level OLD folder name In Utilities pane under "Identity and type" you will see the "Name" entry, change this from the OLD to the new name Just below there is a "Location" entry. Click on a folder with the OLD name and chose the newly renamed folder

步骤4 -重命名Build plist数据

在左侧的“项目导航器”中点击项目,在主面板中选择“Build Settings” 在本节搜索“plist” 在packaging下面,您将看到Info。plist和产品包标识符 重命名Info.plist中的顶部条目 对产品标识符做同样的处理吗

步骤5处理Podfile

In XCode: choose and edit Podfile from the project navigator. You should see a target clause with the OLD name. Change it to NEW. Quit XCode. In terminal, cd into project directory, then: pod deintegrate Run pod install. Open XCode. Click on your project name in the project navigator. In the main pane, switch to the Build Phases tab. Under Link Binary With Libraries, look for the OLD framework and remove it (should say it is missing) The NEWLY named framework should already be there, if not use the "+" button at the bottom of the window to add it If you have an objective-c Bridging header go to Build settings and change the location of the header from OLD/OLD-Bridging-Header.h to NEW/NEW-Bridging-Header.h Clean and run.

在成功地执行了所有步骤之后,您应该能够毫无错误地进行构建

One more thing to note that I don't think has been noted yet is if you are using CoreData objects along with a lazy persistentContainer in the AppDelegate file (or anywhere else), you may get an error saying NSManagedObjectContext is nil (or something along those lines). Change the name for any NSPersistentContainer to use the NEW app name. That should fix the issue! If not, according to this old SO post the solution is to delete your old .xcdatamodeld file and create a new one adding back all the entities again.

除了Luke和Vaiden推荐的所有步骤之外,我还必须重命名Storyboard中的所有customModule属性以匹配新名称,并且这必须区分大小写。