简体   繁体   中英

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.

Now i have nearly 30 classes in this folder.

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

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

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

How to rename the folder with out corrupting the files.

在此处输入图像描述

在此处输入图像描述

Renamed it to myviewcontrollerclasswes

When i renamed

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

Two Solutions

Method_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. Use Xcode to choose base folder:

Rename folder in finder then use Xcode to choose same folder.在此处输入图像描述

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

NOTE as of 2013: Duplicate and rename Xcode project & associated folders


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.

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. Pay attention not to delete them physically only remove them from XCode project, then re-add them and reorganize as you want.

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.

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.

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.

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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