Moving Files into a Real Folder in Xcode

前端 未结 12 985
北恋
北恋 2020-12-02 03:20

When I started my project I was happy to use Groups in Xcode rather than literal folders: Since I\'m using the browser in Xcode to access everything, stuff was nicely organi

相关标签:
12条回答
  • 2020-12-02 03:58

    I've found the most reliable way to work around XCode's appalling design here is to organize ALL your files in Finder, for two reasons:

    1. Finder doesn't make "mistakes", unlike XCode's GUI
    2. Once things are organized in Finder, you can drag/drop entire Finder folders into XCode, and ... it does exactly what you wanted, with no effort

    Even when moving existing XCode files around, it is quicker to do this:

    1. Select the files in Finder
    2. Create a folder in Finder for them
    3. Drag/drop them to the folder (automatically Moves them)
    4. Drag/drop the Finder folder into Xcode (automatically: creates the Xcode folder, adds every file in the Finder folder)
    5. cmd-select every "red" file you now see in Xcode (because you moved them) and hit the delete key

    NB: I never use the "create dragged folders with sub-groups" option, because in XCode 3 that was often hopelessly buggy and could corrupt projects. Apple clearly (IMHO) does NOT use this feature internally, otherwise it would never have been allowed to be so buggy; if Apple doesn't use a thing, it's generally not safe to use it either - they aren't good at testing :)

    0 讨论(0)
  • 2020-12-02 03:59

    Xcode 9

    It seems Xcode 9 now supports it by default. When you move files from a group to another, the file will also be moved from the old folder to the new folder. This was announced in WWDC 2017.

    0 讨论(0)
  • 2020-12-02 04:01

    FURTHER EDITED JUNE 2017: Xcode 9 does this automatically, no special effort required. This answer and Brandon's only apply to Xcode 8 and earlier.

    EDITED DECEMBER 2016: Brandon's answer below is a better solution now. Back when this answer was created in 2010 this was the only option I could find. I now suggest Brandon's answer, below.


    It turns out that moving files into real folders is certainly possible, though not as simple as it should be.

    I got the basic information from a question here, Xcode organising files and folders (core data model objects - iPhone), but learned important things along the way.

    The Process

    Moving the files is a two-step process with multiple sub-steps:

    1. Tell Xcode where you want the files to be:

      • Right/Control-click on the file or file group that you'd like to move and choose Get Info from the contextual menu that appears. The Group Info or File Info window appears.

      • Click the Choose button on the far right side of the window in the Path area. A dialog box appears.

      • Navigate to the folder you want the files to be moved to. Create a New Folder if needed. Click the Choose button in the bottom-right corner of the dialog box, then close the Group Info/File Info window.

      • The names of the file/files in the group will turn red to indicate that Xcode can't find them in the place you specified.

    2. Move the actual files

      • In the Finder (or Git) move the files you selected in step 1 into the actual folders you want them in.

      • Switch back to Xcode. The files/groups should all have turned black again. If any are still red then you've missed moving something to the right folder.

    Tips

    I learned a couple of important things while adjusting the ~300 files in this project:

    • Some files refuse to move this way; that is, when you navigate to the new destination the Choose button is disabled, as is the New Folder button. The solution, though I don't know why it makes a difference, is to first use Xcode to put those files in a Group (right/control-click the files and choose Group, and give the group a name) and then move the group to the new location. After you're actually moved the files in the Finder you can remove them from the group (by dragging them into the new parent group/folder and deleting the group).

    • Stop and build every few minutes, after completing step 2 for a number of files. The build will tell you if you've screwed anything up so far, making it easier to go back and fix it before you've done too much damage.

    • If the files won't move to where you want them to — I had a devil of a time moving some files that had been created early-on in the Classes folder — you can simply drag them out of their old place in the finder to someplace handy like the desktop, delete references to them in Xcode, and then re-import them via the right/control-click Add Existing Files option.

    • If in the past you've used Xcode to delete references to files without also moving them to the trash in this project, you'll find files that don't have to be moved but at just sitting there. Be careful that you don't do what I did, confusing the names of a current group of files I was moving and the older, no-longer-linked files, insisting that Xcode import them because you thought it was being dense.

    Hope this helps some future person. I'm surprised that it was as difficult and occasionally tricky as it was.

    0 讨论(0)
  • 2020-12-02 04:02

    I'm usually move files to the directory directly in the Finder, then fix the files with red-color names in XCode in their "Get Info" dialog: click the "Choose..." button and select file's new locatoin. That's the first response when I want to move files in XCode, and it works.

    0 讨论(0)
  • 2020-12-02 04:05

    A modern (and dead simple!) approach for 2017 (Xcode 6, 7, 8, and sometimes 9, since it does it automagically some of the time):

    If you're moving a bunch of files into a new folder and are keeping the child hierarchy, it's actually a lot easier than moving each file individually:

    1. Create new groups in the Xcode folder tree and organize your files into them however you like.
    2. Create a matching physical folder tree in Finder and organize your physical files into them to match what you did in step 1.
    3. All the references in Xcode should now be red (that's OK!).
    4. From the Identity and Type manager, select the Group in Xcode that you want to relocate, then click the folder icon from the info pane:

    5. In the Finder selection dialog, locate the equivalent new folder you created for this group in step 2. All the files inside that group will now be automagically rediscovered!

    Isn't that nice? At most you'll have to repeat these 5 steps once for each new group you've created (which beats relocating each file individually!)

    Bonus Points!

    Say you accidentally screwed up the move and now a bunch of your files are red and can't be found: select multiple files that are broken, and using the same folder icon in the screenshot from step 4, find the correct folder that contains these files and they'll automatically resolve the missing paths.

    0 讨论(0)
  • 2020-12-02 04:09

    I used the following tool to achieve it.Organize Folders in Groups Xcode

    --no-default-exclusions
    
    0 讨论(0)
提交回复
热议问题