ios 如何在不损坏文件的情况下重命名 xcode 项目中的文件夹名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10006482/
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-08-30 17:42:38  来源:igfitidea点击:

How to rename the folder name in xcode project with out corrupting the files

iphoneobjective-ciosxcodeios4

提问by Ranga

In my xcode project i have created a folder manually named "MyClasses"to place the newly added files/classes to this folder.

在我的 xcode 项目中,我创建了一个手动命名的文件夹,"MyClasses"用于将新添加的文件/类放置到该文件夹​​中。

Now i have nearly 30 classes in this folder.

现在我在这个文件夹中有近 30 个类。

when i renamed this folder , all the files in this folder are gets Erased.

当我重命名这个文件夹时,这个文件夹中的所有文件都被删除了。

Now i need to rename the folder to "ViewControllerClasses".

现在我需要将文件夹重命名为“ ViewControllerClasses”。

But i lost 30 .h, .m, xib files. [lucky i have a copy & and zip file]

但是我丢失了 30 个 .h、.m、xib 文件。[幸运的是我有一个副本和 zip 文件]

How to rename the folder with out corrupting the files.

如何在不损坏文件的情况下重命名文件夹。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Renamed it to myviewcontrollerclasswes

将其重命名为 myviewcontrollerclasswes

When i renamed

当我重命名

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

采纳答案by MrTJ

NOTEas of 2017: Now Xcode 9 synchronises the folder and the project hierarchy automatically.

注意截至 2017 年:现在 Xcode 9 自动同步文件夹和项目层次结构。

NOTEas of 2013: Duplicate and rename Xcode project & associated folders

注意截至 2013 年: 复制并重命名 Xcode 项目和相关文件夹



The "folders" what you see in XCode under your project file are not real folders in the file system, only virtual folders administered in the .xcodeproj file. You can organize your files in the project folder independently from their location in the file system. Some prefers to map the file system folder structure inside the project folder structure, some others store all source files in one big folder in the file system and organize them only in the project folders: it's rather a question of preference.

您在项目文件下的 XCode 中看到的“文件夹”不是文件系统中的真实文件夹,只是在 .xcodeproj 文件中管理的虚拟文件夹。您可以独立于文件系统中的位置来组织项目文件夹中的文件。有些人更喜欢将文件系统文件夹结构映射到项目文件夹结构中,有些人将所有源文件存储在文件系统的一个大文件夹中,并仅在项目文件夹中组织它们:这是一个偏好问题。

However if you rename/move physicallythe files in the file system, you will have to delete and re-add them to your project since XCode will not know where to find them. Pay attention not to delete them physicallyonly remove them from XCode project, then re-add them and reorganize as you want.

但是,如果您重命名/移动身体在文件系统中的文件,则必须删除并重新添加到您的项目,因为的XCode不知道在哪里可以找到他们。注意不要物理删除它们,只是从 XCode 项目中删除它们,然后重新添加它们并根据需要重新组织。

One more thing to note: if you are using version control system you will have to inform also its client (svn or git most likely) that you have renamed/moved your files. If you want to keep file revision history it will be a good idea to issue the copy/move command explicitly to the version control otherwise it will treat your files as deleted from the old location and added as new in the new location.

还有一点要注意:如果您使用版本控制系统,您还必须通知其客户端(最有可能是 svn 或 git)您已重命名/移动文件。如果您想保留文件修订历史记录,最好向版本控制明确发出复制/移动命令,否则它会将您的文件视为从旧位置删除并在新位置添加为新文件。

回答by Guru

Two Solutions

两种解决方案

Method_1. Try Manual editing:

方法_1。尝试手动编辑:

  ? Drag your MedChart.xcodeproj to TextWrangler  (or any text editor) 

  ? Use find button to find "FolderName" (Your folder name) 

  ? Replace all with new name.

  ? In some project you may notice header search path problem...goto header search path and replace with new name.

Method_2. Use Xcode to choose base folder:

方法_2。使用 Xcode 选择基本文件夹:

Rename folder in finder then use Xcode to choose same folder. enter image description here

在 finder 中重命名文件夹,然后使用 Xcode 选择相同的文件夹。 在此处输入图片说明

回答by Shady

In case anyone is still having trouble with this:

如果有人仍然遇到这个问题:

  1. Select the folder or file in the left-side bar of XCode corresponding to the folder you want to rename (for me I renamed the folder containing all my files so I selected the topmost folder)
  2. On the right-side bar, below where it says 'Location', click the folder icon.
  3. In the file explorer that opens up rename the existing folder to whatever name you'd like it to be, then afterwards select it and press 'Ok'.
  4. XCode should update the file locations accordingly.
  1. 在XCode左侧栏中选择要重命名的文件夹对应的文件夹或文件(对我来说,我重命名了包含我所有文件的文件夹,所以我选择了最上面的文件夹)
  2. 在右侧栏的“位置”下方,单击文件夹图标。
  3. 在打开的文件资源管理器中,将现有文件夹重命名为您想要的任何名称,然后选择它并按“确定”。
  4. XCode 应相应地更新文件位置。

Keep in mind that if you rename something which contains a file that is hard-coded as a certain path in your build settings, XCode will throw an error. You'll have to manually change those paths in your build settings.

请记住,如果您重命名包含在构建设置中硬编码为特定路径的文件的内容,XCode 将抛出错误。您必须在构建设置中手动更改这些路径。

This worked for me, hope it works for you too.

这对我有用,希望它也适用于你。

回答by Daniel

You should just run a search and replace on the project file (if you are working with version control and with other developers you will have seen this file a lot without a doubt), it's the project.pbxprojfile located inside the xxxxxxxx.xcodeproj file.

您应该只在项目文件上运行搜索和替换(如果您正在使用版本控制和其他开发人员,您将毫无疑问地经常看到这个文件),它是project.pbxproj位于 xxxxxxxx.xcodeproj 文件中的文件。

Just right click (Control + Click) on the file and select "Show Package Contents" to find the xcodeproj file.

只需右键单击(Control + 单击)文件并选择“显示包内容”即可找到 xcodeproj 文件。