I have an Xcode project with the following group structure:
ProjectName/ Classes/ class1.h class1.m class2.h class2.m ... XMLDocs/ doc1.xml doc2.xml ... Resources/ Info.plist MainMenu.xib ...
and so on and so forth.
I'd like this to be represented in the folder structure on the disk as well:
ProjectFolder/ Project.xcodeproj Classes/ class1.h class1.m class2.h class2.m ... XMLDocs/ doc1.xml doc2.xml ... Resources/ Info.plist MainMenu.xib ...
as opposed to the usual everything in the root project folder methodology.
Is there any way to do this without manually creating the folder structure on the disk and then having to repoint all the reference in Xcode to the new location?
Bonus points if you can tell me how to do this automatically any time I create a new group or add files to an existing group in Xcode.
You can create a new group, with its own folder, directly in Xcode, but it's not at all obvious. Instead of choosing 'New Group', choose 'Add Files to “<Project>”'. Then, in the file picker dialog, click the New Folder button or press Command-Shift-N and type the name of the new folder/group.
Xcode offers several ways to add existing files and folders to your project: Drag the files from the Finder into the Project navigator. Click the Add button (+) in the Project navigator's filter bar, and choose Add Files to “projectName”. Choose File > Add Files to “projectName”.
Xcode relies on filesystem organization by keeping a reference to a "physical" file or folder. That is why you may have all the classes, images, plists, and other parts of your projects stored in the same folder, while the references to these parts are being kept organized into respective groups within Xcode project.
You can do this to some extent! There's just one extra step to do every time you create a new group (and this first time you'll have a lot of catching up to do!):
Whenever you create a group in Xcode, immediately select it and open the righthand sidebar. Notice the "Location:" setting just below its name. Click the folder icon next to "None" and set it to a new folder with the same name.
Now, whenever you add files to the group, they'll head to the corresponding folder on disk. Woo!
Unfortunately, this initial time, you'll have a lot of file-moving to do. (As you change the group paths, your files will all turn red, as Xcode will begin looking for them in the new folder. You'll have to manually move them from the Finder to fix it.) There is, however, a command-line tool to perform this initial migration for you: https://github.com/venmo/synx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With