我有一个项目叫XXX。我想把这个项目重命名为YYY。
请注意,XXX是一个非常常见的术语(例如:“数据”,或者简单的“项目”),因此一个简单的RegEx搜索和替换是不可能的,因为有破坏项目配置文件的风险。
我的当前项目目录包含以下项目:
XXX XXXTests XXX . xcodeproj
我想把它们重命名为:
年年 年 YYY.xcodeproj
... 分别与必要的变化反映在我的项目文件。
我如何才能在不手动创建和填充新项目的情况下实现这一点呢?
我有一个项目叫XXX。我想把这个项目重命名为YYY。
请注意,XXX是一个非常常见的术语(例如:“数据”,或者简单的“项目”),因此一个简单的RegEx搜索和替换是不可能的,因为有破坏项目配置文件的风险。
我的当前项目目录包含以下项目:
XXX XXXTests XXX . xcodeproj
我想把它们重命名为:
年年 年 YYY.xcodeproj
... 分别与必要的变化反映在我的项目文件。
我如何才能在不手动创建和填充新项目的情况下实现这一点呢?
当前回答
为卢克-韦斯特的精彩回答补充一点:
使用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.
加入卢克·韦斯特的公认答案。如你有任何权益:
关闭Xcode 更改授权文件名 进入Xcode,选择授权文件应该突出显示为红色,在文件检查器中选择文件夹图标,并选择您的重命名文件。 进入构建设置,搜索“授权”并更新授权的文件夹名称和文件名。 清洁和重建
为卢克-韦斯特的精彩回答补充一点:
使用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.
更改项目名称;
在project导航器中选择您的项目。 在文件检查器的Identity and Type部分中,在name字段中输入一个新名称。 按Return键。 将显示一个对话框,列出项目中可以重命名的项。该对话框包括更改后项目将如何显示的预览。 若要选择性地重命名项,请禁用不想重命名的任何项的复选框。若要仅重命名应用程序,请保持应用程序已选中,并取消选择所有其他项。 按“重命名”