Is it possible to sort the Compile Sources list in the Build Phases section of an Xcode project?

前端 未结 5 1115
梦如初夏
梦如初夏 2021-02-02 11:04

I want to sort the files in the \'Compile Sources\' section of my Xcode project according to their names. Is it possible?

5条回答
  •  日久生厌
    2021-02-02 11:41

    Yes, you can reorder the Compile Sources section in Xcode, but not from the GUI - which is a shame considering that this is already version 6 of the IDE and they still haven't gotten around to this basic feature.

    As A-Live said, you need to edit the project.pbxproj file within the yourproject.xcodeproj file. Use Finder to select the yourproject.xcodeproj file and then use the context menu to Show Package Contents. After that open the project.pbxproj file with a text editor.

    Find the PBXSourcesBuildPhase section and copy everything between files = ( and ); into a new text file. Remove the leading tabs/spaces. Save that file somewhere on your disk. Open up a terminal and do this:

     sort -bf -t " " -k 3 PBXSourcesBuildPhase.txt > PBXSourcesBuildPhase.sorted.txt
    

    Open up the new PBXSourcesBuildPhase.sorted.txt file in your text editor, copy the sorted lines into the PBXSourcesBuildPhase section of your project.pbxproj (overwrite the lines that you previously copied) and save.

    Now you should be able to see all the files sorted in the Compile Sources section in Xcode.

    I've tested this in Xcode 6.0.1 with a small project (~150 source files) and had no problems.

    Careful: you should make a backup of your project file (or better: use version control) before you try this. Just in case.

提交回复
热议问题