Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 979
med Avatar asked Jun 20 '14 11:06

med


People also ask

What are build phases Xcode?

Xcode also uses instances of the Copy Files build phase to embed frameworks, app extensions, app clips, and other content inside your bundle. You use these build phases to copy other project files into a bundle. For example, you might copy templates for new documents into your app's bundle.

What is Srcroot?

$(SRCROOT) (aka $(SOURCE_ROOT) ) is a path to your location where a .

What is Built_products_dir?

BUILT_PRODUCTS_DIR. Description: Directory path. Identifies the directory under which all the product's files can be found. This directory contains either product files or symbolic links to them.


2 Answers

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.

like image 147
daniel Avatar answered Oct 14 '22 05:10

daniel


I reckon it is a shame that this is not possible.

as a workaround in most of situations, you can use the search filter on the right upper corner of the file list.

for example, I needed to add a compiler flag in many files which (fortunately) all started with the same prefix. to do so, as stated here, you have to double click on a file.

then, I filtered the files for the prefix, shift-clicked them in order to select them all, then released shift and double-clicked one of them. this way I was able to add the flag to all of the files at once

like image 21
Fabio Napodano Avatar answered Oct 14 '22 05:10

Fabio Napodano