Changing Folder Name in Xcode


Gerriet M. Denkmann
 

I have a project:

Some Folder
Some.xcodeproj
Old and Bad Name
lots of stuff

I would like to change the folder “Old and Bad Name” to “Nice new name”

I could rename this folder in Finder and then reimport “lots of stuff” into Xcode.
But this is very tedious and error prone.

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/project.pbxproj - but I am afraid of messing with Xcode's private files.

Can Xcode (Version 8.3.3 (8E3004b)) do this for me? Some sort of refactoring?

Gerriet.


Quincey Morris
 

On Aug 8, 2017, at 03:50 , Gerriet M. Denkmann <g@...> wrote:

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/project.pbxproj - but I am afraid of messing with Xcode's private files.

I wouldn’t edit the .pbxproj file. Under the assumption that your project has the files organized under yellow group “folder” icons (in the navigator pane, as opposed to blue “folder reference” icons), you can go ahead and rename the folder to its new name. (For Xcode 8, you should close the project before doing this, because this version has a bug where it doesn’t update the visuals of the navigator pane properly when a file appears or disappears. Re-open the project after the rename.)

When you get back to Xcode, all your source files will have turned red (in the navigator pane). Make sure the File tab of the utilities pane is shown. Select the top-level yellow group icon, then click on the tiny gray folder-like button under its name in the Files tab. You’ll get a standard open dialog, which you can use to choose a new (real) folder to associate with the group icon. Simply choose the newly-renamed folder. Then close and re-open the project, again because of the cosmetic bug mentioned above.

If all of your source file groups are relative to this base folder, all your files should now be black in the navigator. But, if any of the subgroups had other kinds of paths, you will need to repeat the previous step for each one that contains red files, choosing the relevant folder each time.

There’s one final step. There are some files specified by path in settings. Typically this includes the info.plist and the prefix header, if any. You will need to fix those relative paths manually in settings.

HOWEVER, if your project is under git source control, doing all this will likely bork your repository pretty well. AFAIK, Xcode 8 isn’t smart enough to change the relative paths inside the repository. In this case, you should probably find some other piece of software to update the names in the repository *first*, then re-open the project in Xcode and fix the groups’ paths.

ALTERNATIVELY, if you’re prepared to open your project in Xcode 9, it can handle this situation correctly. Before renaming anything, select the top level yellow group icon that contains your source code files. (This should be the one that has your bad old name.) In the navigator pane, select that group and press Enter to edit the name. When you change the name and press Enter, Xcode will rename the folder, and update all of the git information that depends on it. As before, if you have sub-groups that aren’t relative to this group, you’ll have to handle them in a separate step, and you’ll have to change a couple of build settings manually.


Ben Kennedy
 

On 08 Aug 2017, at 10:16 am, Quincey Morris <quinceymorris@...> wrote:

HOWEVER, if your project is under git source control, doing all this will likely bork your repository pretty well. AFAIK, Xcode 8 isn’t smart enough to change the relative paths inside the repository. In this case, you should probably find some other piece of software to update the names in the repository *first*, then re-open the project in Xcode and fix the groups’ paths.
If you're using Git, this can be mitigated by simply using `git mv` to rename the directory (`git mv oldname newname`).

b


Alex Zavatone
 

On Aug 8, 2017, at 5:50 AM, Gerriet M. Denkmann <g@...> wrote:

I have a project:

Some Folder
Some.xcodeproj
Old and Bad Name
lots of stuff

I would like to change the folder “Old and Bad Name” to “Nice new name”

I could rename this folder in Finder and then reimport “lots of stuff” into Xcode.
But this is very tedious and error prone.

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/project.pbxproj - but I am afraid of messing with Xcode's private files.

Can Xcode (Version 8.3.3 (8E3004b)) do this for me? Some sort of refactoring?

Gerriet.
On the right side of the project in one of the inspectors, there is a means of specifying the path to the item selected and how it is defined. Relative to Group, Relative to Project, Absolute Path, etc…

You can also duplicate your folder, set up the new name and then select the new path to the item from the inspector.

Does that help?

- Alex Zavatone


Sean McBride
 

On Tue, 8 Aug 2017 17:50:13 +0700, Gerriet M. Denkmann said:

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/
project.pbxproj - but I am afraid of messing with Xcode's private files.
I've done that, and it's worked fine for me.

Can Xcode (Version 8.3.3 (8E3004b)) do this for me? Some sort of refactoring?
If the files are referenced relative it their parent, then I think it's just a matter of re-pointing the folder. Go to Xcode File Inspector > Identity and Type > Location and click that little grey folder icon (that doesn't look like a button at all, of course).

Cheers,

Sean


Gerriet M. Denkmann
 

Thanks to all who responded!

In my Xcode project, the yellow group “folder” icons in the navigator pane closely resemble the folder structure of my project. And I do not use git or similar.

This is what I did:

1. make sure that all relevant files had in the File inspector → Identity & Type → Location = Relative to Group

2. In Finder I duplicated and renamed the folder

3. Xcode File inspector → Identity & Type → Location clicked the Folder Icon and set the file name to new folder.

4. in Finder removed the old folder.

There were some glitches: I had to remove the. xcconfig things and add them again.
And some file are mentioned in Build Settings (e.g. Info.plist, .entitlement).
But these were minor issues.

Your hint with the folder-icon button in Xcode → File inspector → Identity & Type → Location proved to be extremely helpful.
Thanks to Quincey and Sean for mentioning this.

Kind regards,

Gerriet.