Sorting of files in Xcode

Discussion in 'iOS Programming' started by anmldr, Sep 16, 2008.

  1. anmldr macrumors member

    Jul 14, 2008
    I would like to alphabetically sort files that are in my Resources
    folder. They seem to be listed in the order that I added them to the
    project. This is a drug formulary and I am using UIWebView to view a
    couple of hundred drug sheets. How can I specify that Xcode show the
    files in alphabetical order and not in the order that I add them to
    the that I can easily find the file to do some editing?

  2. ghayenga macrumors regular

    Jun 18, 2008
    Assuming you're reading those files into an NSArray or NSMutableArray look at the documentation for SortUsingSelector.
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    You want to sort the listing of these files in the project window right?

    I don't think there is any built-in feature to do this. You're not the first person to ask. I think it would be possible to do this with applescript but it might take longer to write the script than just do it. Not sure if anyone has ever written such a script and posted it.

    The project file is an xml file and you could conceivably open the pbxproj file in a text editor and sort the relevant lines.
  4. anmldr thread starter macrumors member

    Jul 14, 2008
    That is correct. I solved the problem by deleting all of the files from the project window. But, I only deleted the references to these files. Then I went to the folder and (since they are sorted alphabetically in the folder) I re-added all of the files to the project and ta..da! Now they are in alphabetical order :)

    Not the ideal way of doing something like this since you could accidentally delete a file or forget to add a file back into the project.

    Thanks. This might be a good bug to submit to Apple or a suggested improvement for Xcode. I just thought that I was missing something.

    Thank you very much for your reply.
  5. tedsmith3rd macrumors member

    Aug 30, 2006
  6. glmonte macrumors newbie

    Oct 21, 2008
    Xcode is a stupid IDE...

    Can't do simple things like sorting files. I have more than 100 files in the Resources folder and whenever I would like to rename/delete a file I'm wasting my time to find the file(s).
  7. jarruda macrumors newbie

    Apr 12, 2009
    Xcode does indeed have built-in sorting. It's just not in the most intuitive of places.

    First, select the folder that you would like sorted.
    Now, go to the Edit menu in the main menu bar, and select Sort>By Name.
    Ta da! Sorted files.

    Unfortunately this doesn't keep it sorted, so you have to do it any time that you add files, but at least it is there.

    Extra tip that I forgot to mention: Because this functionality is in the menu, you're able to very easily bind a key to it. Personally I used the shortcut key for making a snapshot because I never use it; so all I have to do is highlight the folder I want sorted and press ctrl-apple-s and voila, it's sorted.
  8. almo2001 macrumors newbie

    Jun 9, 2009
    Praise the lord!!! THANK YOU FOR THAT!

Share This Page