简体   繁体   English

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

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

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.但是我丢失了 30.h、.m、xib 文件。 [lucky i have a copy & and zip file] [幸运的是我有一份 & 和 zip 文件]

How to rename the folder with out corrupting the files.如何在不损坏文件的情况下重命名文件夹。

在此处输入图像描述

在此处输入图像描述

Renamed it to myviewcontrollerclasswes将其重命名为 myviewcontrollerclasswes

When i renamed当我改名

在此处输入图像描述在此处输入图像描述

Two Solutions两种解决方案

Method_1.方法_1。 Try Manual editing:尝试手动编辑:

  « 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.方法_2。 Use Xcode to choose base folder:使用 Xcode 选择基本文件夹:

Rename folder in finder then use Xcode to choose same folder.在 finder 中重命名文件夹,然后使用 Xcode 选择相同的文件夹。在此处输入图像描述

NOTE as of 2017: Now Xcode 9 synchronises the folder and the project hierarchy automatically.注意截至 2017 年:现在 Xcode 9 自动同步文件夹和项目层次结构。

NOTE as 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.您在项目文件下的 XCode 中看到的“文件夹”并不是文件系统中的真实文件夹,只是在 .xcodeproj 文件中管理的虚拟文件夹。 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.有些人更喜欢 map 项目文件夹结构中的文件系统文件夹结构,有些人则将所有源文件存储在文件系统中的一个大文件夹中,并且只在项目文件夹中组织它们:这是一个偏好问题。

However if you rename/move physically the 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.但是,如果您重命名/物理移动文件系统中的文件,您将不得不删除它们并将它们重新添加到您的项目中,因为 XCode 不知道在哪里可以找到它们。 Pay attention not to delete them physically only remove them from XCode project, then re-add them and reorganize as you want.注意不要物理删除它们,只能从 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.还有一件事要注意:如果您使用的是版本控制系统,您还必须通知其客户端(最有可能是 svn 或 git)您已重命名/移动文件。 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.如果你想保留文件修订历史,最好向版本控制明确发出复制/移动命令,否则它会将你的文件视为从旧位置删除并在新位置添加为新文件。

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) Select XCode 左边栏中你要重命名的文件夹对应的文件夹或文件
  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'.在打开的文件资源管理器中,将现有文件夹重命名为您想要的任何名称,然后将其命名为 select 并按“确定”。
  4. XCode should update the file locations accordingly. 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.请记住,如果您重命名包含在构建设置中硬编码为特定路径的文件的内容,XCode 将引发错误。 You'll have to manually change those paths in your build settings.您必须在构建设置中手动更改这些路径。

This worked for me, hope it works for you too.这对我有用,希望它也对你有用。

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.pbxproj file located inside the xxxxxxxx.xcodeproj file.您应该只在项目文件上运行搜索和替换(如果您正在使用版本控制和其他开发人员,您毫无疑问会经常看到这个文件),它是位于 xxxxxxxx.xcodeproj 文件中的project.pbxproj文件.

Just right click (Control + Click) on the file and select "Show Package Contents" to find the xcodeproj file.只需右键单击(Control + 单击)文件和 select“显示 Package 内容”即可找到 xcodeproj 文件。

I still find it easier than all these methods to simply create a new folder in your file navigator and then drag your files from the other folder into it.我仍然发现它比所有这些方法更容易,只需在文件导航器中创建一个新文件夹,然后将文件从另一个文件夹拖到其中。 Sometimes the simplest way is the best way.有时最简单的方法就是最好的方法。 It literally takes me 10 seconds and I don't need to leave Xcode.它确实需要我 10 秒,我不需要离开 Xcode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM