kdbdallas
kdbdallas

Reputation: 4543

Sort File List in Xcode?

Is there a way in Xcode to sort my list of files under say the Classes folder Alphabetically?

I know I can drag them around, but with tons of files that is a pain.

I am surprised I can not right click on the folder and say to sort.

Upvotes: 37

Views: 7664

Answers (5)

Zayin Krige
Zayin Krige

Reputation: 3308

There isn't really an easy solution in XCode5.

  • I opened the pbxproj file in a text editor.
  • Navigate down to /* Begin PBXResourcesBuildPhase section */
  • select everything in files.
  • copy to a new text document.
  • Replace /* with \t (tab character)
  • select all, copy and paste into blank excel document. you should have 2 columns of data
  • insert a column at poisition 2
  • make all rows for that column /*
  • sort the sheet on column 3
  • copy all data and paste back over your section in pbxproj file
  • save file

That should sort the "Copy Bundle Resources" section of your project.

I feel dirty just doing this, but hey - it works

Upvotes: 0

Cœur
Cœur

Reputation: 38737

The ruby script from jedediah works great. To also sort resources being copied, you can add:

state = :group if line =~ /^\s*files\s*=\s*\x28\s*$/

Note that sort is case sensitive (capital letters first). To make it insensitive, use:

group << [$1.downcase,line]

Upvotes: 0

jedediah
jedediah

Reputation: 1219

Here is a Ruby script that will sort all the files within their respective groups in an Xcode 4 project file (probably Xcode 3 as well but I haven't tried that).

Usage:

ruby sort.rb <infile> <outfile>

where <infile> is an unsorted .pbxproj file and <output> will be the sorted version. Don't make them the same file.

#!/usr/bin/env ruby

state = :primary
group = []
file_count = group_count = 0

File.open ARGV[0] do |infile|
  File.open ARGV[1], 'w' do |outfile|
    infile.each_line do |line|
      case state

      when :primary
        # copy lines until and including "children = ("
        outfile.write line
        state = :group if line =~ /^\s*children\s*=\s*\x28\s*$/

      when :group
        if line =~ /^\s*[0-9A-F]+\s*\/\* (.*) \*\/,\s*$/
          # add file to current group if "<guid> /* <filename> */,"
          group << [$1,line]
          file_count += 1

        else
          # otherwise, output sorted files,
          # empty the group, and go back to primary state
          group.sort.each do |fn,ln|
            outfile.write ln
          end

          state = :primary
          group = []
          outfile.write line
          group_count += 1
        end

      end
    end
  end
end

puts "Sorted #{file_count} files in #{group_count} groups"

Upvotes: 4

Nicki
Nicki

Reputation: 984

Czar there are advantages to having it the way you want, instead of automatically having it sort at all times.

Some classes might be related in some way, but the names aren't right next to each other, I've used that for certain. :)

Upvotes: -1

Kevin Griffin
Kevin Griffin

Reputation: 14662

Click on the folder, and then click Edit > Sort > By Name

Upvotes: 41

Related Questions