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

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

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

XXX XXXTests XXX . xcodeproj

我想把它们重命名为:

年年 年 YYY.xcodeproj

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

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


当前回答

Xcode 11.0 +。

现在真的很简单了。只需转到Project Navigator,即Xcode窗口的左侧面板。 按Enter键使其激活以进行重命名,就像更改文件夹名称一样。

只需要在这里更改新名称,Xcode会要求你重命名其他东西。

.

点击这里的重命名,你就完成了。

如果你对根文件夹的名称感到困惑,比如为什么它没有改变,那么它只是一个文件夹。它只是用一个新名字重新命名它。

其他回答

当遵循@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.

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

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

我在网上找到了一些有用的简单步骤:

in Finder change project's folder name open project/select project file in Xcode navigator/show the file inspector/under Identity and Type change Name as per your preference/Enter/wait few seconds till pop-up window appears/click rename/again wait few seconds - do not push OK/ select folder under project file in Xcode navigator/show the file inspector/under Identity and Type change name as per your preference/Enter/wait few secont till file under project file in Xcode nagivator changes its name in Xcode project status bar click on the project name (it appears when you hover over the beginning of line)/choose Manage schemes...till "Autocreate schemes" window shows up/2x click on project name under scheme column/enter/close "Autocreate schemes" window select project file in Xcode navigator/inXcode editor ~ interface builder area choose tab "Build setting"/in filter type the previous name of your project/click enter/in the line(s) where the previous name of your project appears within the root(s) - just change it to new name voala that's it

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

使用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.

步骤1 -重命名项目

在Xcode窗口左侧面板的“项目导航器”中单击要重命名的项目。 在右边的面板中,选择“文件检查器”,你的项目的名称应该在“身份和类型”下面。把它改成你的新名字。 当对话框询问是否重命名 项目的内容项,点击“重命名”。对任何关于未提交更改的警告说“是”。

步骤2 -重命名方案

注意:对于Xcode 14, 2022年9月:在某些情况下,当Xcode执行上面的第一步时,Xcode现在会自动重命名方案。如果是这样,在步骤2中就没有什么可做的了。

在窗口的顶部中间,即活动设备/模拟器的左侧,在旧名称下有您的产品的方案;点击并按住它,然后选择“管理方案…”。 点击方案中的旧名称(类似于Xcode中的重命名文件),它将变成可编辑的;更改名称并点击“关闭”。

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

Quit Xcode. Rename the master folder that contains all your project files. In the correctly-named master folder, beside your newly-named .xcodeproj file, there is probably a wrongly-named OLD folder containing your source files. Rename the OLD folder to your new name. {If you use git you could use git mv oldname newname. Note that when using git mv old new you generally must (i) completely commit all other changes (ii) only then git mv old new (iii) commit that (iv) only then make further changes. If steps i-ii-iii-iv are followed, git will maintain history through the rename.} Re-open the project in Xcode. If you see a warning "The folder OLD does not exist", dismiss the warning. The source files in the renamed folder will have red names because the path to them has broken. In the "Project navigator" in the left-hand panel, click on the top-level folder representing the OLD folder you renamed. In the right-hand panel, under "Identity and Type", change the "Name" field from the OLD name to the new name. Just below that field is a "Location" menu. If the full path has not corrected itself, click on the nearby folder icon and choose the renamed folder. You may have to perform this fix for each source file if the links to them remain broken.

步骤4 -重命名Build plist数据

Click on the project in the "Project navigator" on the left, and in the main panel select "Build Settings". Search for "plist" in the settings. In the Packaging section, you will see fields for Info.plist and Product Bundle Identifier. If there is a file name entered in Info.plist, update it (it may have been updated automatically in Step 1). Do the same for Product Bundle Identifier, unless it is utilizing the ${PRODUCT_NAME} variable. In that case, search for "product" in the settings and update Product Name. If Product Name is based on ${TARGET_NAME}, click on the actual target item in the TARGETS list on the left of the settings pane and edit it, and all related settings will update immediately. Search the settings for "prefix" and ensure that Prefix Header's path is also updated to the new name. If you use SwiftUI, search for "Development Assets" and update the path. Enclose in double-quotes ("") quotes if the path contains a space ( ). If you have an entitlements file, search for "signing" and update Code Signing Entitlements. Accordingly, rename the actual entitlements file in the Project Navigator also. (Side note: In Xcode 13 entitlements files have a yellow checkmark icon in the Project Navigator; you may have created one if e.g. you use shared containers/App Groups.)

步骤5 -重复步骤3的测试(如果你有的话)

步骤6 -如果核心数据的名称与项目名称(如果有的话)匹配,则重复步骤3

步骤7 -清理和重建你的项目

命令+ Shift + K清理 命令+ B建造

进一步指出。

如果项目有故事板。

At this stage, open the overall folder simply in the Mac finder. Type the old name in the file text search. You will see that the old name appears very often as customModule="OldName" in all storyboard files. (Explanation.) These can be fixed, in Xcode, one by one, on each storyboard: Tap on the view controller. Tap on the Identity Inspector (4th small button) in the right hand panel. Look at the Custom Class -> Module field. Notice it seemingly shows NewName. However (still as of Xcode14) it's incorrect. Simply tap the drop-down, and explicitly select the new name. (If you now review that storyboard file with a text editor, you will see it is fixed.) You may prefer to change them all just using a plain text editor.