重命名 xcode 4 项目和实际文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8262613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:11:15  来源:igfitidea点击:

Renaming xcode 4 project and the actual folder

xcodexcode4directoryrename

提问by Chris G.

I know how to rename the project in Xcode 4, but how do you rename the source folder? The thing is that renaming the project in Xcode, does only rename within Xcode (Though it is progress compared to previous) - but why Xcode is not renaming the folder in the filesystem I don't know.

我知道如何在 Xcode 4 中重命名项目,但是如何重命名源文件夹?问题是在 Xcode 中重命名项目,只会在 Xcode 内重命名(尽管与以前相比有所进步) - 但为什么 Xcode 没有重命名我不知道的文件系统中的文件夹。

回答by Nick Lockwood

You can do this from within Xcode without resorting to hand editing the pbxproj file in a text editor!

您可以在 Xcode 中执行此操作,而无需在文本编辑器中手动编辑 pbxproj 文件!

Here's how:

就是这样:

  1. Rename your source folder in the Finder. This will break the project initially because Xcode doesn't automatically detect when the real folders that the virtual (yellow) project folders point to are changed, so all the files inside that folder will turn red in Xcode. Don't worry about that, we'll fix it in step 3.

  2. In Xcode, click on the (now broken) virtual folder in the left-hand sidebar and rename it to match the name in the Finder (you can actually call it anything you want, or not rename it at all, but that would be insane). That won't fix the red files inside the folder, but that's OK.

  3. In the right-hand sidebar in Xcode, click the icon shown in the screenshot below to bring up a file dialog. Select the folder that you previously renamed. This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside.

  4. In your build settings, search for the old folder name and manually rename any occurrences you find. There will typically be two of them, oldfolder/prefix.pch and oldfolder/info.plist, but there may be others.

  1. 在 Finder 中重命名源文件夹。这最初会破坏项目,因为 Xcode 不会自动检测虚拟(黄色)项目文件夹指向的真实文件夹何时发生更改,因此该文件夹中的所有文件在 Xcode 中都将变为红色。别担心,我们会在第 3 步中修复它。

  2. 在 Xcode 中,单击左侧边栏中的(现已损坏的)虚拟文件夹并将其重命名以匹配 Finder 中的名称(您实际上可以将其命名为您想要的任何名称,或者根本不重命名,但这会很疯狂)。这不会修复文件夹内的红色文件,但没关系。

  3. 在 Xcode 的右侧边栏中,单击下面屏幕截图中显示的图标以显示文件对话框。选择您之前重命名的文件夹。这会将虚拟文件夹与磁盘上的真实文件夹重新关联,并将自动修复指向其中所有文件的链接。

  4. 在您的构建设置中,搜索旧文件夹名称并手动重命名您找到的任何匹配项。通常有两个,oldfolder/prefix.pch 和 oldfolder/info.plist,但也可能有其他的。

All done!

全部完成!

enter image description here

在此处输入图片说明

EDIT: this option is still there in Xcode 5, but is helpfully hidden by default. To show it, click the thin "Identity and Type" header in the inspector above the "Text Settings" panel to expand it.

编辑:这个选项在 Xcode 5 中仍然存在,但默认情况下隐藏起来很有帮助。要显示它,请单击“文本设置”面板上方检查器中细小的“身份和类型”标题以将其展开。

回答by djromero

I've done it dozens of times:

我已经做了几十次了:

  • Rename the Project by clicking then editing the Title in your Xcode Project Navigator.
  • Close Xcode.
  • Rename the source folder.
  • From the Finder, open the .pbxprojfile inside project bundle (context menu "Show Package Contents") with any text editor.
  • Search and replaceany occurrence of the original folder name with the new folder name.
  • Save the file.
  • Open Xcode project.
  • 通过单击然后在 Xcode 项目导航器中编辑标题来重命名项目。
  • 关闭 Xcode。
  • 重命名源文件夹。
  • 在 Finder 中,.pbxproj使用任何文本编辑器打开项目包内的文件(上下文菜单“显示包内容”)。
  • 搜索并用新文件夹名称替换任何出现的原始文件夹名称。
  • 保存文件。
  • 打开 Xcode 项目。

回答by Philip007

Task: Rename "Play" to "Play2" both in Xcode and in Finder

任务: 在 Xcode 和 Finder 中将“Play”重命名为“Play2”

Change this:

改变这个:

enter image description here

在此处输入图片说明

To this:

对此:

enter image description here

在此处输入图片说明

STEPS:

脚步:

// Before anything, please backup the project in Finder!

// 在任何事情之前,请先在 Finder 中备份项目!

  • Rename project in Xcode Project navigator // Click project name then hit enter
  • Rename group in Xcode Project navigator // not affecting folder name in Finder
  • Close Xcode
  • Rename outer folder (left column in image) in Finder
  • 在 Xcode 项目导航器中重命名项目 // 单击项目名称然后按 Enter
  • 在 Xcode 项目导航器中重命名组 // 不影响 Finder 中的文件夹名称
  • 关闭 Xcode
  • 在 Finder 中重命名外部文件夹(图像中的左列)

// All above steps are straight-forward and without side effects // // Now comes the tricky part: rename the inner folder (middle column in image) in Finder (the one at the same level with .xcodeproj)

// 以上所有步骤都很简单,没有副作用 // // 现在是棘手的部分:重命名 Finder 中的内部文件夹(图像中的列)(与 .xcodeproj 处于同一级别的文件夹)

  • Rename the inner folder in Finder while keeping Xcode closed
  • Right click .xcodeproj, select "Show Package Contents"
  • Open .pbxproj file with Mac TextEdit
  • Search and replace all "Play" with "Play2". To guarantee everything goes right, click the arrow on the left end of the search bar and modify the search attribute. Change "Contains" to "Full word", and uncheck "Ignore case"
  • Save .pbxproj file
  • Open Xcode project and Run
  • 重命名 Finder 中的内部文件夹,同时保持 Xcode 关闭
  • 右键单击 .xcodeproj,选择“显示包内容”
  • 使用 Mac TextEdit 打开 .pbxproj 文件
  • 搜索并用“Play2”替换所有“Play”。为确保一切顺利,请单击搜索栏左端的箭头并修改搜索属性。将“包含”更改为“完整单词”,并取消选中“忽略大小写”
  • 保存 .pbxproj 文件
  • 打开Xcode项目并运行

回答by Mav55

Here is how to rename a project effectively in XCode4 (INCLUDING THE FILES FOLDER):

以下是如何在 XCode4 中有效地重命名项目(包括文件文件夹):

  1. Close all open projects completely in XCode to prevent any issues
  2. Copy the Project in question to a new Folder (IMPORTANT: KEEP A BACKUP OF YOUR OLD PROJECT)
  3. Open the Project
  4. Rename the Project itself in XCode4 (double click on the project name), change the name and follow the steps (yes to everything)
  5. Go to product, manage schemes and rename the scheme (double click on the scheme name)
  6. Close your project (make sure is completely closed otherwise the next steps will not work)
  7. In Finder go to the Project folder and right click on the .xcodeproj file, then select the option "Show Package Contents"
  8. Then right click on the .pbxproj file and open it with TextEdit
  9. Replace all occurrences of the Folder Name where the projects used to live (The old project name for the new project name)
  10. Save the file
  11. Open the Project again and Build it!
  1. 在 XCode 中完全关闭所有打开的项目以防止出现任何问题
  2. 将有问题的项目复制到新文件夹(重要:保留旧项目的备份)
  3. 打开项目
  4. 在 XCode4 中重命名项目本身(双击项目名称),更改名称并按照步骤操作(是的)
  5. 转到产品,管理方案并重命名方案(双击方案名称)
  6. 关闭您的项目(确保完全关闭,否则接下来的步骤将不起作用)
  7. 在 Finder 中,转到 Project 文件夹并右键单击 .xcodeproj 文件,然后选择选项“Show Package Contents”
  8. 然后右键单击 .pbxproj 文件并使用 TextEdit 打开它
  9. 替换项目曾经所在的所有文件夹名称(新项目名称的旧项目名称)
  10. 保存文件
  11. 再次打开项目并构建它!

回答by Chris G.

First of - dont rename an Xcode project!!!

首先 - 不要重命名 Xcode 项目!!!

If you have to, the beneath could be it - I never got it to work, ended up creating a new project and started all over copying in the existing files. Xcode is so ahh.... It has so many non productive things, like also try renaming a file from "Name" to "name". Well, well have fun.

如果必须,下面可能就是它 - 我从来没有让它工作,最终创建了一个新项目并开始在现有文件中复制。Xcode 太棒了......它有很多非生产性的东西,比如还尝试将文件从“名称”重命名为“名称”。嗯,玩得开心。

I found the answer or how to work around this: Open the pbxproj file by right clicking "Show Package Content" and in there you edit a project.pbxproj file - you have to rename a reference called path and some other stuff - just search for the folder name added "/".

我找到了答案或如何解决此问题:通过右键单击“显示包内容”打开 pbxproj 文件,然后在其中编辑 project.pbxproj 文件 - 您必须重命名名为 path 的引用和其他一些内容 - 只需搜索文件夹名称添加了“/”。

That is it. Hope it helps some one.

这就对了。希望它可以帮助某人。

回答by mlev

I am summing up for myself, after examining various answers above and trying myself. Let's assume the current project name is ProjAbc and you want to rename it to ProjDef:

在检查了上面的各种答案并尝试自己之后,我正在为自己总结。让我们假设当前项目名称是 ProjAbc 并且您想将其重命名为 ProjDef:

  1. Exit Xcode of that project.

  2. In Finder, Duplicate the folder ABOVE ProjAbc.xcodeproj for backup.

  3. In Finder, Rename freely the folder ABOVE ProjAbc.xcodeproj if you feel you need it to suit new project name.

  4. In Finder, Rename the source files folder parallel to ProjAbc.xcodeproj from ProjAbc to ProjDef

  5. Open Xcode for ProjAbc.xcodeproj (in Project Navigator, all files in virtual source folder ProjAbc will be in Red color).

  6. In Xcode, click on the (now broken) virtual folder in the Project Navigator in the left-hand sidebar and rename it to match the name in Finder - ProjDef. That won't yet fix the red files inside the folder, but that's OK.

  7. In Xcode, (still selecting the virtual folder in the left-hand sidebar) in the right-hand sidebar, in the File inspector, click the icon shown in the screenshot below to bring up a file dialog. In the file dialog, select the folder that you previously renamed (ProjDef). This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside. Picture shows where to click the Folder icon in File inspector

  8. In Xcode, in Project Navigator, click on the ProjAbc project name, and rename it to ProjDef.

    • You will be prompted: "Rename project content items?". Click "Rename" button.
    • You will be prompted: "Would you like Xcode to take automatic snapshots before Project Rename and similar operations?". Click either "Disable" or "Enable". It does not matter.
  9. In Xcode, now open "Build Settings" inside ProjDef target (inside project ProjDef in Project Navigator). Rename both foldername and filename of both *-Info.plist and *-Prefix.pch files to contain ProjDef instead of ProjAbc.

  10. In Xcode, in Project Navigator, in ProjDef virtual sources folder, in "Supporting Files", also rename again both *-Info.plist and *-Prefix.pch files to contain ProjDef instead of ProjAbc

  11. In Xcode Menu, press Product/Scheme/Manage Schemes... (or click "ProjAbc"> Scheme name in Scheme Bar at left top of Xcode, and press "Manage Schemes...") and in the dialog box rename Scheme from ProjAbc to ProjDef, then press "OK" button. If Project name is composed of single word, you may run it just now!

  12. In Xcode, edit the top comment line in Supporting Files/*-Prefix.pch file, and replace ProjAbc by ProjDef (2 times). Of course correcting this comment is optional.

  13. Exit Xcode.

  14. In Finder, point to ProjDef.xcodeproj and open it in text editor. (Either open it in TextWrangler.app , or, mouse right-click and in the pop-up menu press "Show Package Contents" then edit file project.pbxproj in TextEdit.app)

  15. In the Text Editor, search "ProjAbc" (Entire Word, Match Case) which should appear once (in paragraph: /* Begin PBXNativeTarget section */ in line: productName = ProjAbc;) and replace it by "ProjDef". Indeed, project could run anyway!, so this step is optional.

  16. if project name is composed of 2 or more separate words, like "ProjDef Geh", then you MUST do next steps: Search for the reference to the Finder folder of the virtual source files folder -

    • Search for the line: path = ProjDef Geh;
    • It will appear once, in paragraph /* ProjDef Geh */
    • Replace it by the line: path = "ProjDef Geh";
  17. Save from text editor, and exit the Text Editor.

  18. That's it. As written above, if project name is composed of single word, you can run right at end of step 11.

  1. 退出该项目的 Xcode。

  2. 在 Finder 中,复制 ABOVE ProjAbc.xcodeproj 文件夹进行备份。

  3. 在 Finder 中,如果您觉得需要它以适应新的项目名称,请自由重命名 ABOVE ProjAbc.xcodeproj 文件夹。

  4. 在 Finder 中,将与 ProjAbc.xcodeproj 平行的源文件文件夹从 ProjAbc 重命名为 ProjDef

  5. 打开 Xcode for ProjAbc.xcodeproj(在 Project Navigator 中,虚拟源文件夹 ProjAbc 中的所有文件都将显示为红色)。

  6. 在 Xcode 中,单击左侧边栏中 Project Navigator 中的(现已损坏的)虚拟文件夹,并将其重命名以匹配 Finder - ProjDef 中的名称。这还不能修复文件夹中的红色文件,但没关系。

  7. 在 Xcode 中,(仍然选择左侧边栏中的虚拟文件夹)在右侧边栏中,在文件检查器中,单击下面屏幕截图中显示的图标以显示文件对话框。在文件对话框中,选择您之前重命名的文件夹 (ProjDef)。这会将虚拟文件夹与磁盘上的真实文件夹重新关联,并将自动修复指向其中所有文件的链接。 图片显示在文件检查器中单击文件夹图标的位置

  8. 在 Xcode 中,在 Project Navigator 中,单击 ProjAbc 项目名称,并将其重命名为 ProjDef。

    • 系统将提示您:“重命名项目内容项?”。单击“重命名”按钮。
    • 你会被提示:“你希望 Xcode 在 Project Rename 和类似操作之前自动拍摄快照吗?”。单击“禁用”或“启用”。没关系。
  9. 在 Xcode 中,现在在 ProjDef 目标(在项目导航器中的项目 ProjDef 内)中打开“构建设置”。重命名 *-Info.plist 和 *-Prefix.pch 文件的文件夹名和文件名以包含 ProjDef 而不是 ProjAbc。

  10. 在 Xcode 中,在 Project Navigator 中,在 ProjDef 虚拟源文件夹中,在“Supporting Files”中,再次重命名 *-Info.plist 和 *-Prefix.pch 文件以包含 ProjDef 而不是 ProjAbc

  11. 在 Xcode Menu 中,按 Product/Scheme/Manage Schemes...(或在 Xcode 左上角的 Scheme Bar 中单击“ProjAbc”> Scheme name,然后按“Manage Schemes...”)并在对话框中将 Scheme 重命名为ProjAbc 到 ProjDef,然后按“确定”按钮。如果项目名称由单个单词组成,您可以立即运行它!

  12. 在 Xcode 中,编辑 Supporting Files/*-Prefix.pch 文件中最上面的注释行,将 ProjAbc 替换为 ProjDef(2 次)。当然,更正此评论是可选的。

  13. 退出Xcode。

  14. 在 Finder 中,指向 ProjDef.xcodeproj 并在文本编辑器中打开它。(在 TextWrangler.app 中打开它,或者鼠标右键单击并在弹出菜单中按“显示包内容”然后在 TextEdit.app 中编辑文件 project.pbxproj)

  15. 在文本编辑器中,搜索应该出现一次的“ProjAbc”(整个单词,匹配大小写)(在段落中:/* Begin PBXNativeTarget section */ 行中:productName = ProjAbc;)并将其替换为“ProjDef”。确实,项目无论如何都可以运行!所以这一步是可选的。

  16. 如果项目名称由 2 个或更多单独的单词组成,例如“ProjDef Geh”,那么您必须执行以下步骤: 搜索对虚拟源文件文件夹的 Finder 文件夹的引用 -

    • 搜索行:path = ProjDef Geh;
    • 它将出现一次,在 /* ProjDef Geh 段 */
    • 用以下行替换它: path = "ProjDef Geh";
  17. 从文本编辑器保存,然后退出文本编辑器。

  18. 就是这样。如上所述,如果项目名称由单个单词组成,则可以在步骤 11 的末尾运行。

回答by Zampano

Here is another issue that you should be aware of while replacing values in your *.pbxproj file. If your old folder name was FooBar you will have an entry in your *.pbxproj file that looks like this:

这是您在替换 *.pbxproj 文件中的值时应该注意的另一个问题。如果您的旧文件夹名称是 FooBar,您的 *.pbxproj 文件中将有一个条目,如下所示:

path = FooBar

路径 = FooBar

Suppose your new folder name is Foo Bar. That is, you are introducing a space. Then, this line should become

假设您的新文件夹名称是 Foo Bar。也就是说,您正在引入一个空间。那么,这条线应该变成

path = "Foo Bar"

路径 = "Foo Bar"

If you just do a simple find and replace, the result will be a *.pbxproj file that Xcode can't parse. If your new folder name has a space and the old name didn't have a space, be sure to include the double quotes.

如果你只是做一个简单的查找和替换,结果将是一个 Xcode 无法解析的 *.pbxproj 文件。如果您的新文件夹名称有空格而旧名称没有空格,请务必包含双引号。

回答by Hadoren

I found the above answers really useful, especially Nick Lockwood's answer.

我发现上述答案非常有用,尤其是 Nick Lockwood 的答案。

I just renamed a couple of folders in Xcode 8 and encountered two more issues: A) "missing from working copy errors"B) Core Data crashes.

我刚刚在 Xcode 8 中重命名了几个文件夹,并遇到了另外两个问题:A) “缺少工作副本错误”B) Core Data crashes

How to resolve these two issues:

如何解决这两个问题:

A) "missing from working copy errors"

A) “从工作副本错误中丢失

I found the below answer very useful: Swift 3 / Xcode 8 Upgrade - 100's of DerivedData files missing from working copy errors

我发现以下答案非常有用:Swift 3 / Xcode 8 Upgrade - 100's of DerivedData files missing from working copy errors

Basically Xcode 8 has rigorous source control, which can lead to the above errors. You have to:

基本上 Xcode 8 有严格的源代码控制,这可能会导致上述错误。你必须:

  1. Clean Xcode derived data.
  2. Go to Source Control and click Refresh Status.
  3. Go to Source Control and click Commit; select all the files on the left sidebar of the commit menu when committing (right click -> Select All).
  4. You'll probably get an error.
  5. Close the Commit menu.
  6. Refresh Status.
  7. Close your project by quitting Xcode.
  8. Reopen your project, refresh status, commit again.
  9. This time the commit should work.
  10. Click Project -> Clean.
  1. 清理 Xcode 派生数据。
  2. 转到源代码管理并单击刷新状态。
  3. 转到源代码管理并单击提交;提交时选择提交菜单左侧边栏上的所有文件(右键单击-> 全选)。
  4. 你可能会得到一个错误。
  5. 关闭提交菜单。
  6. 刷新状态。
  7. 通过退出 Xcode 关闭您的项目。
  8. 重新打开您的项目,刷新状态,再次提交。
  9. 这次提交应该有效。
  10. 单击项目 -> 清理。

I'm assuming that you have already enabled Source Control. If you haven't, or if you get stuck following my instructions, just follow the more detailed instructions in the link provided.

我假设您已经启用了源代码管理。如果您还没有,或者如果您无法按照我的说明进行操作,请按照提供的链接中的更详细说明进行操作。

B) Core Data crashes

B)核心数据崩溃

Renaming folders will sometimes screw up Core Data. There are several possible reasons why this is so, and below are some fixes I can suggest:

重命名文件夹有时会搞砸 Core Data。造成这种情况的可能原因有多种,以下是我可以建议的一些修复方法:

  1. Incorrect AppDelegatemodel name. This was the case in my situation. Go to your AppDelegate and find let container = NSPersistentContainer(name: "YOUR CORE DATA MODEL NAME"). Make sure that the name is correct.

    In the future (several years after this post, when Apple changes Core Data again) or if you're using an older version of Core Data, take a careful look at AppDelegate. There's probably something funky there that's messing with your Core Data.

  2. Incorrect model name in xcdatamodeld. Go to Finder and open your .xcdatamodeld in a text editor.

  1. AppDelegate模型名称不正确。这就是我的情况。转到您的 AppDelegate 并找到let container = NSPersistentContainer(name: "YOUR CORE DATA MODEL NAME"). 确保名称正确。

    将来(这篇文章几年后,当 Apple 再次更改 Core Data 时)或者如果您使用的是旧版本的 Core Data,请仔细查看 AppDelegate。那里可能有一些时髦的东西干扰了您的核心数据。

  2. xcdatamodeld 中的模型名称不正确。转到 Finder 并在文本编辑器中打开您的 .xcdatamodeld。

Check the following:

检查以下内容:

<plist version="1.0">
  <dict>
     <key>_XCCurrentVersionName</key>
     <string>YOUR CORE DATA MODEL NAME.xcdatamodel</string>  <-- Make sure this is correct.
  </dict>
</plist>

More detail here: Core Data model files does not load on rename

更多细节在这里:核心数据模型文件不会在重命名时加载

  1. If the two things above don't work, try to 1) delete your entity and then add another entity that's identical or 2) delete your xcdatamodeld and then add another data model that's identical (and make sure that the name of the new xcdatamodeld matches what is in your AppDelegate and the rest of your code). Never do this with a live App- or if you do this, make sure to properly migrate your Core Data whilst doing so.
  1. 如果上述两件事不起作用,请尝试 1) 删除您的实体,然后添加另一个相同的实体或 2) 删除您的 xcdatamodeld,然后添加另一个相同的数据模型(并确保新 xcdatamodeld 的名称匹配您的 AppDelegate 和其余代码中的内容)。切勿使用实时应用程序执行此操作- 或者如果您执行此操作,请确保在执行此操作时正确迁移您的核心数据。

回答by Ravi Kumar

If you are have old reference of source project into your project, When dublicate the project (every change made affect to both proejct) here the solution

如果您的项目中有源项目的旧参考,则在此处复制项目(每个更改都会影响两个项目)时,解决方案

  • Dublicate Project from source project
  • Rename source folder of source project that break reference issue.
  • In dublicate proejct everything goes red choose your current folder of project. (screenshot is shows in green tick answer of stackoverflow)
  • 从源项目复制项目
  • 重命名破坏参考问题的源项目的源文件夹。
  • 在复制项目中,一切都变红了,选择您当前的项目文件夹。(屏幕截图显示在 stackoverflow 的绿色勾号答案中)

========================================================================

================================================== ======================