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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/239139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:25:08  来源:igfitidea点击:

Sort File List in Xcode?

xcode

提问by kdbdallas

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

Xcode 中有没有办法按字母顺序对 Classes 文件夹下的文件列表进行排序?

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.

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

回答by Kevin Griffin

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

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

回答by jedediah

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).

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

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.

其中 <infile> 是未排序的 .pbxproj 文件,<output> 将是排序后的版本。不要使它们成为同一个文件。

#!/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 << [,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"

回答by C?ur

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

来自 jedediah 的 ruby​​ 脚本效果很好。要对正在复制的资源进行排序,您可以添加:

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 << [.downcase,line]

回答by Zayin Krige

There isn't really an easy solution in XCode5.

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
  • 我在文本编辑器中打开了 pbxproj 文件。
  • 向下导航到 /* 开始 PBXResourcesBuildPhase 部分 */
  • 选择文件中的所有内容。
  • 复制到一个新的文本文档。
  • 将 /* 替换为 \t(制表符)
  • 全选,复制粘贴到空白excel文件中。你应该有 2 列数据
  • 在位置 2 插入一列
  • 使该列的所有行 /*
  • 对第 3 列的工作表进行排序
  • 复制所有数据并粘贴回 pbxproj 文件中的部分
  • 保存存档

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

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

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

我觉得这样做很脏,但是嘿 - 它有效

回答by Nicki

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

Czar 以您想要的方式拥有它是有好处的,而不是始终自动对其进行排序。

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

有些类可能以某种方式相关,但名称彼此不相邻,我确实使用过。:)