创建Xcode组作为文件系统文件夹的工作流程 [英] Workflow to create Xcode groups as file system folders

查看:333
本文介绍了创建Xcode组作为文件系统文件夹的工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在Xcode 4项目导航器窗格中将类组织成组.我还通过终端使用GIT版本控制,这对我来说比Xcode 4集成更好.对我来说,当我在Xcode中创建的组与文件系统上的真实文件夹相对应时,这才是最有意义的.

I like organizing my classes into groups, in the Xcode 4 project navigator pane. I also use GIT versioning via the terminal, which works better for me than the Xcode 4 integration. To me it makes the most sense when the groups I create in Xcode correspond to real folders on my file system.

但是,Xcode似乎并不关心文件(例如,Objective-C .h/.m文件)在文件系统上的位置,并且每次添加组(Option+Command+N)时,对于任何文件来说,它都是纯修饰的您放入的硬盘将与其余硬盘共享相同的位置.

However, Xcode seems to not care about where a file (e.g. Objective-C .h/.m file) is on the filesystem, and every time you add a group (Option+Command+N) it's purely cosmetic, for any files you put in there will share the same location on your hard drive as the rest.

奇怪的是,如果您首先在硬盘驱动器上创建一个文件夹,然后将其拖动到Xcode,则您已经创建了一个在文件系统上具有其自己位置的组.您在其中创建的每个文件都会在磁盘上的文件夹中创建.我很喜欢,但是如果Xcode在Option+Command+N为我做到这一点,我会更喜欢它.对于要创建的每个组都切换到Finder,然后将其拖回到项目导航器中的正确位置,这很愚蠢.

The weird thing is, that if you first create a folder on your hard drive, and then drag it to Xcode, you have created a group with its own location on your file system. Every file you create in there will be created in the folder on disk. I love that, but I'd love it even more if Xcode would do that for me at Option+Command+N. The workflow of switching to Finder for every group you want to create and then dragging it back to the right place in your project navigator is just plain silly.

感觉设置可以修复,但是我找不到!有更好的方法吗?

It feels like something a setting would fix, but I can't find it! Is there a better way?

更新:将文件夹拖到Xcode时,将出现一个对话框,您可以在其中选择文件夹参考".这看起来很有希望,但是我的Xcode 4不接受其​​中的文件作为类,并不断告诉我它找不到任何文件.答案可能就在这里,但我仍然找不到.

Update: When dragging a folder to Xcode, you'll get a dialog window where you can choose "Folder Reference". That looks promising, however my Xcode 4 doesn't accept the files in there as classes and keeps telling me it can't find any files. Maybe the answer lies here somewhere, but I still can't find it.

另一个更新::我已将主编辑器环境从Xcode更改为AppCode.后者支持实际创建文件夹以支持项目组,同时保持与Xcode的100%兼容性.那些AppCode家伙肯定知道他们在做什么.

Another update: I've changed my main editor environment from Xcode to AppCode. The latter supports actually creating folders to back the project groups, while maintaining 100% compatibility with Xcode. Those AppCode guys sure know what they're doing.

推荐答案

更新

以下介绍Xcode 9及更高版本.

UPDATE

The following describes Xcode 9 and later.

从Xcode 9开始,当您在项目中创建组时,Xcode可以自动创建文件系统文件夹.

Beginning with Xcode 9, Xcode can automatically create a filesystem folder when you create a group in your project.

在项目导航器中右键单击(或按住Control键单击)时,上下文菜单将包含新建组"菜单项,并且其中一个带有文件夹的新建组"菜单项没有文件夹的新组"菜单项.

When you right-click (or control-click) in the project navigator, the context menu will include a "New Group" menu item and either a "New Group with Folder" menu item or a "New Group without Folder" menu item.

  • 如果Xcode提供新组"和带文件夹的新组",则新组"将创建一个没有文件夹的组.

  • If Xcode offers "New Group" and "New Group with Folder", then "New Group" creates a group without a folder.

如果Xcode提供新组"和没有文件夹的新组",则新组"将创建一个包含文件夹的组.

If Xcode offers "New Group" and "New Group without Folder", then "New Group" creates a group with a folder.

换句话说,"New Group"在文件夹创建方面总是与其他(显式)菜单项相反.

In other words, "New Group" always does the opposite of the other (explicit) menu item, with regard to folder creation.

如果重命名一个组,并且该组具有对应的相同名称的文件夹,则Xcode 9也会重命名该文件夹.

If you rename a group, and that group has a corresponding folder with the same name, Xcode 9 also renames the folder.

在Xcode 9中,如果将文件从一个组拖到另一个组中,并且这些组具有不同的文件夹,则Xcode 9会将文件移动到新组的文件夹中,而不管新组的文件夹名称是否与该组相同

In Xcode 9, if you drag a file from one group to another, and the groups have different folders, Xcode 9 moves the file to the new group's folder, regardless of whether the new group's folder has the same name as the group.

如果不希望在Xcode 9中出现此行为,则可以从命令行设置未记录的设置:

If you do not want this behavior in Xcode 9, you can set an undocumented setting from the command line:

defaults write com.apple.dt.Xcode IDEDisableStructureEditingCoordinator -bool YES

无法推断出带文件夹的新组"和没有文件夹的新组"的详细信息

Xcode决定是显示新组"和带文件夹的新组",还是新组"和不带文件夹的新组",这一点都不明显. WWDC 2018的一名Apple工程师(我想他的名字叫Paul)查看了Xcode源代码并向我解释了它:

Impossible-to-deduce details about "New Group with Folder" and "New Group without Folder"

It's not at all obvious how Xcode decides whether to show "New Group" and "New Group with Folder", or "New Group" and "New Group without Folder". An Apple engineer at WWDC 2018 (I think his name was Paul) looked at the Xcode source code and explained it to me:

  • Xcode会找出您单击的组(或者,如果您未单击组,则会找出包含您单击的项的组).
  • Xcode会查看属于所单击组的子组的子组(和链接的文件夹).
  • 如果大多数子组都有自己的文件夹,则Xcode假定您希望新组也有自己的文件夹.因此Xcode显示"New Group"(将创建一个文件夹)和"New Group Without Folder".
  • 如果大多数子组都拥有自己的文件夹,则Xcode假定您希望新组也拥有自己的文件夹.因此,Xcode显示新建组"(将创建文件夹)和新建组与文件夹".
  • 如果恰好有一半的子组都有自己的文件夹,我不知道Xcode如何打破常规,而且我现在不希望对其进行测试……
  • 如果单击的组没有子组,则Xcode会根据单击的组本身是否具有自己的文件夹来决定要显示的内容.
  • Xcode figures out which group you clicked on (or, if you didn't click a group, it figures out which group contains the item you clicked).
  • Xcode looks at the subgroups (and linked folders) that are children of the clicked group.
  • If the majority of the subgroups have their own folders, then Xcode assumes you want the new group to also have its own folder. So Xcode shows "New Group" (which will create a folder) and "New Group without Folder".
  • If the majority of the subgroups do not have their own folders, then Xcode assumes you want the new group to also not have its own folder. So Xcode shows "New Group" (which will not create a folder) and "New Group with Folder".
  • I don't know how Xcode breaks the tie if exactly half of the subgroups have their own folders, and I don't feel like testing it right now…
  • If the clicked group has no subgroups, Xcode decides what to show based on whether the clicked group itself has its own folder.

基本上,Xcode会根据其未来的兄弟姐妹是否也拥有自己的文件夹来猜测您的新组是否应该拥有自己的文件夹.

Basically, Xcode tries to guess whether your new group should have its own folder based on whether its future siblings have their own folders.

可以直接在Xcode中创建一个具有自己文件夹的新组,但这一点并不明显.

You can create a new group, with its own folder, directly in Xcode, but it's not at all obvious.

选择向<项目>"添加文件",而不是选择新建组".然后,在文件选择器对话框中,单击新建文件夹"按钮或按Command-Shift-N并键入新文件夹/组的名称.然后,确保选择为任何添加的文件夹创建组",然后单击添加"或按Return键.

Instead of choosing ‘New Group’, choose ‘Add Files to "<Project>"’. Then, in the file picker dialog, click the New Folder button or press Command-Shift-N and type the name of the new folder/group. Then, make sure "Create groups for any added folders" is chosen and click Add or press Return.

如果您需要将现有文件移动到新组中,这不会为您节省很多,因为Xcode仍然不会这样做.

但是,如果您要创建一个新组来保存新文件,确实会节省一些步骤.

But it does save a few steps if you are creating a new group to hold new files.

这篇关于创建Xcode组作为文件系统文件夹的工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆