代码之家  ›  专栏  ›  技术社区  ›  kdbdallas

在Xcode中对文件列表进行排序?

  •  37
  • kdbdallas  · 技术社区  · 17 年前

    有办法进去吗 项目 按字母顺序对Classes文件夹下的文件列表进行排序?

    我知道我可以拖动它们,但处理大量文件很痛苦。

    我很惊讶我不能右键单击文件夹并说要排序。

    5 回复  |  直到 11 年前
        1
  •  40
  •   Kevin Griffin    17 年前

    单击文件夹,然后单击编辑>排序>按名称

        2
  •  4
  •   jedediah    15 年前

    这是一个Ruby脚本,它将对Xcode 4项目文件中各自组内的所有文件进行排序(可能还有Xcode 3,但我还没有尝试过)。

    用途:

    ruby sort.rb <infile> <outfile>
    

    其中<infile>是一个未排序的.pbxproj文件,<输出>将是排序后的版本。不要把它们放在同一个文件里。

    #!/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"
    
        3
  •  1
  •   Cœur Gustavo Armenta    14 年前

    jedediah的红宝石字体效果很好。要对正在复制的资源进行排序,您可以添加:

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

    请注意,排序区分大小写(大写字母优先)。要使其不敏感,请使用:

    group << [$1.downcase,line]
    
        4
  •  0
  •   Zayin Krige    12 年前

    XCode5中并没有一个简单的解决方案。

    • 我在文本编辑器中打开了pbxproj文件。
    • 导航到/*开始PBX资源BuildPhase部分*/
    • 选择文件中的所有内容。
    • 复制到新的文本文档。
    • 将/*替换为\t(制表符)
    • 全选,复制并粘贴到空白excel文档中。您应该有2列数据
    • 在姿势2处插入一列
    • 为该列创建所有行/*
    • 将表格按第3列排序
    • 复制所有数据并粘贴回pbxproj文件中的部分
    • 保存文件

    这应该会对项目的“复制捆绑资源”部分进行排序。

    我这么做就觉得很脏,但嘿,它奏效了

        5
  •  -1
  •   Nicki    15 年前

    沙皇,以你想要的方式拥有它是有好处的,而不是随时自动排序。

    有些类可能在某种程度上是相关的,但名称不是紧挨着的,我肯定会用它。 :)