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

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

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

XXX XXXTests XXX . xcodeproj

我想把它们重命名为:

年年 年 YYY.xcodeproj

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

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


当前回答

更改项目名称;

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

其他回答

步骤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.

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

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

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.

Xcode 11.0 +。

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

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

.

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

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

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

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