How should I organize my Xcode project files?

Viewed 12371

I'm trying to wrap my head around Xcode's file organization - or lack there of. I can do all I want in project and it looks great with all the "fake" folders and structure. I go look at the file system and boom HUGE mess. I've tried importing files with the Create Folder Reference for any added folder option checked and that works, kinda. I get the structure I want both in Xcode and on the filesystem.

Issues: When I add a file to a folder on the filesystem that is a Folder Reference in Xcode, its not in Xcode when I go look, not even after reloading the project. Files/Subfolders in a Folder Reference can't be moved around in Xcode. When I move them on the filesystem I get red links (can't find the file?) in Xcode.

How do I keep a organized project and filesystem? How can I set up a project to just recognize a folder and show its (current and up-to-date) files and subfolders in my project?

Another issue I seem to run into, if I use a Folder Reference and change a file, the file is not updated in my application unless I do a full clean & rebuild. If I don't use a Folder Reference, all my files are dumped into the Resource folder of the application bundle, not in the nice structure I have in my project.

Should I care at all? Should I just use the fake folders and let everything go everywhere and not care? My application bundle will be a mess, the filesystem will be a mess, but it will all work... I would hope?

Edit:

My biggest reason for wanting an organized filesystem is that the resource files (images, sounds, other datafiles, etc.) are not edited in Xcode. I have to access them in 3rd party apps via the filesystem. If its a mess things are harder to find and maintain in the other 3rd party applications.

Also what happens if I want a structure like the following:

  • Images/Backgrounds/Name.png
  • Images/Icons/Name.png
  • Images/Titles/Name.png

Should I use long filenames rather than folders to organize?

  • Images_Backgrounds_Name.png
  • Images_Icons_Name.png
  • Images_Titles_Name.png
8 Answers

This changed with Xcode 9. From the release notes:

Groups in the Project Navigator are now more closely associated with directories in the file system. (28612132)

  • Dragging files between groups in the Project Navigator moves the files in the filesystem and updates any associated SCM working copies.
  • When a group is connected to folder in the filesystem, creating, renaming, and deleting groups updates the corresponding files and folders in the the filesystem.
  • To remove a connection between a group and a folder in the filesystem, select the group, and then open the File inspector and click on the on the Clear path button (X).
  • To add or update an association from a file or a folder in the filesystem to a file or a group in the project, select the file or group, open the File inspector, and drag the corresponding file or folder onto the Location section in the File inspector.

The new behaviour is available from the 'New Group with Folder' command (which may appear as just 'New Group'), while the old behaviour is available from the 'New Group without Folder' command (which may also appear as just 'New Group'!) The dominant usage amongst any existing groups in the target folder seems to determine which command gets labelled 'New Group'. It's more than a little confusing, but if you are in the habit of choosing one or the other, the idea seems to be that you can just stick with the default 'New Group' command. (See rob mayoff's far more thorough explanation.)

Related