Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-organize groups and folders in a project created before Xcode 9

Tags:

xcode

ios

I am working on a project that was created before Xcode 9, and the folder structure doesn't match the groups structure.

There are groups that are not associated to folders, and other that are. Some files are outside folders while they are in groups.

  1. Is there a way to automatically ask Xcode to change the folders structure to match the groups in Xcode?
  2. If there is no automated way, what would be the manual procedure? My guess: open the folders, move all the files and folders until all of them are at the right place, matching the Xcode groups (pretty tedious), and then re-associate all folders and files that have become red in Xcode. When that will have been done, Xcode 9 will then allow any future change to be a match group-folder (PS: I started doing this, but exclamation marks appear next to files names even after associating them to their file).
like image 722
Kqtr Avatar asked Jan 18 '18 09:01

Kqtr


People also ask

How do I group files 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.

How do I add folders to Xcode project?

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”.


1 Answers

After unsuccessfully trying Synx, I ended up understanding everything I needed to do to accomplish this (manually), so here's how one should proceed:

  1. In Xcode, create your groups without worrying about them having a folder or not. Create the structure that you would like and move your files into these groups (in Xcode).
  2. In the Finder, replicate that folder structure, and drag your files into the folders and subfolders. Files that you move around might get lost by Xcode and become red (a red file means that Xcode does not know where that file is in the Finder) and that's fine, you will re-attach them at the next step:

enter image description here

  1. Now start by linking the groups to their folders (when you link a group to its folder, all the files inside that group will try to link to their file in that folder, and that saves you time). Click on a group in Xcode, and in the File Inspector, click the folder icon, and go select the folder in Xcode.

enter image description here

FYI, if you a group was already linked to a folder that is now incorrect, the folder icon might become a little cross, to remove that reference. If your group appears in red, you can click that and override the link towards the new folder.

  1. Inside that group that you have just linked to its folder, not all files will automatically find their reference and become black; some will stay red. You could right-click each of these files and link them to their file using the File inspector, but there is a quicker way: select all the files inside a group, and go in the File inspector to link them. In the Finder window that will appear, select their folder and click OK. All of the files in that folder/group will then be correctly linked.

  2. If there are individual files that are still red after fixing your folders, you can then link them to their file in the folder using the File Inspector, until all of them are black.

  3. IMPORTANT: if you see a "?" or "!" sign next to a file name, it's ok. You just need to "git add" this file using the terminal ("git add -A" to add all at once), and it will then appear as "Renamed" (you will see "R" sign in Xcode). Renamed is what you want for all your files, you should not have "?" or "!" left.

Tip:

  • A group that is not linked to a folder has a different folder icon in Xcode than a group with folder. The goal is therefore to only have plain icons, without the little arrow:

enter image description here

  • You will only need to do this cleaning once. Once your groups are linked to folders and if you use Xcode, your files will automatically be created in the folder link to their group (unless you specifically select "New group WITHOUT folder" in Xcode).
  • Commit regularly if you are not 100% confident at first. You could for instance commit whenever you have successfully re-ordered one group/folder. However, your only issue will probably be those ? and !, and you now know how to fix that -by git adding them.
like image 110
Kqtr Avatar answered Oct 19 '22 04:10

Kqtr