将 Xcode 组创建为文件系统文件夹的工作流程
我喜欢在 Xcode 4 项目导航器窗格中将我的类组织成组。我还通过终端使用 GIT 版本控制,这比 Xcode 4 集成更适合我。对我来说,当我在 Xcode 中创建的组对应于我的文件系统上的真实文件夹时,这是最有意义的。
但是,Xcode 似乎并不关心文件(例如 Objective-C .h/.m 文件)在文件系统上的位置,并且每次添加组(Option+Command+N
)时,它都会纯粹是装饰性的,因为您放入其中的任何文件都将与其他文件共享硬盘驱动器上的相同位置。
奇怪的是,如果您首先在硬盘上创建一个文件夹,然后将其拖到 Xcode,您就创建了一个在文件系统上拥有自己位置的组。您在其中创建的每个文件都将在磁盘上的文件夹中创建。我喜欢这个,但如果 Xcode 能够通过 Option+Command+N
为我做到这一点,我会更喜欢它。对于要创建的每个组切换到 Finder,然后将其拖回项目导航器中的正确位置,这种工作流程简直是愚蠢的。
感觉好像某个设置可以修复某些问题,但我找不到它!有更好的办法吗?
更新:将文件夹拖到 Xcode 时,您将看到一个对话框窗口,您可以在其中选择“文件夹引用”。这看起来很有希望,但是我的 Xcode 4 不接受其中的文件作为类,并且一直告诉我它找不到任何文件。也许答案就在这里某个地方,但我仍然找不到。
另一个更新:我已将主编辑器环境从 Xcode 更改为 AppCode。后者支持实际创建文件夹来支持项目组,同时保持与 Xcode 100% 的兼容性。那些 AppCode 的人肯定知道他们在做什么。
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.
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.
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?
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新
以下描述 Xcode 9 及更高版本。
从 Xcode 9 开始,当您在项目中创建组时,Xcode 可以自动创建文件系统文件夹。
当您在项目导航器中右键单击(或按住 Control 键单击)时,上下文菜单将包含“新建组”菜单项和“带文件夹的新建组”菜单项或“不带文件夹的新组”菜单项。
如果 Xcode 提供“新建组”和“带文件夹的新建组”,则“新建组”会创建一个不带文件夹的组。
如果 Xcode 提供“新建组”和“不带文件夹的新建组”,则“新建组”会创建一个带有文件夹的组。
换句话说,在文件夹创建方面,“新建组”始终执行与其他(显式)菜单项相反的操作。
如果您重命名一个组,并且该组有一个同名的相应文件夹,则 Xcode 9 也会重命名该文件夹。
在 Xcode 9 中,如果将文件从一个组拖动到另一个组,并且这些组具有不同的文件夹,则 Xcode 9 会将文件移动到新组的文件夹,无论新组的文件夹是否与该组同名。
如果您不希望在 Xcode 9 中出现此行为,您可以从命令行设置一个未记录的设置:
无法推断有关“带文件夹的新组”和“不带文件夹的新组”的详细
信息Xcode 如何决定是否显示“新组”和“带文件夹的新组”,或者“新组”和“不带文件夹的新组”并不明显。 WWDC 2018 上的一位 Apple 工程师(我想他的名字叫 Paul)查看了 Xcode 源代码并向我解释了这一点:
基本上,Xcode 会尝试根据其未来的同级组是否有自己的文件夹来猜测您的新组是否应该有自己的文件夹。
原始
您可以直接在 Xcode 中创建一个具有自己的文件夹的新组,但这一点也不明显。
不要选择“新组”,而是选择“将文件添加到“<项目>””。然后,在文件选择器对话框中,单击“新建文件夹”按钮或按 Command-Shift-N 并键入新文件夹/组的名称。然后,确保选择“为任何添加的文件夹创建组”,然后单击“添加”或按 Return 键。
如果您需要将现有文件移动到新组中,这不会为您节省太多,因为 Xcode 仍然不会这样做。
但它确实节省了如果您要创建一个新组来保存,只需几个步骤新文件。
UPDATE
The following describes Xcode 9 and later.
Beginning with Xcode 9, Xcode can automatically create a filesystem folder when you create a group in your project.
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.
If Xcode offers “New Group” and “New Group with Folder”, then “New Group” creates a group without a folder.
If Xcode offers “New Group” and “New Group without Folder”, then “New Group” creates a group with a folder.
In other words, “New Group” always does the opposite of the other (explicit) menu item, with regard to folder creation.
If you rename a group, and that group has a corresponding folder with the same name, Xcode 9 also renames the folder.
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.
If you do not want this behavior in Xcode 9, you can set an undocumented setting from the command line:
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:
Basically, Xcode tries to guess whether your new group should have its own folder based on whether its future siblings have their own folders.
ORIGINAL
You can create a new group, with its own folder, directly in Xcode, but it's not at all obvious.
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.
This doesn't save you much if you need to move existing files into the new group, because Xcode still won't do that.
But it does save a few steps if you are creating a new group to hold new files.
对于那些懒得同步文件夹的人来说,GitHub 上有一个不错的工具。
Synx 是一个命令行工具,可以重新组织 Xcode 项目文件夹以匹配您的 Xcode 组。
希望这对某人有帮助
For those who are too lazy to synchronize the folders, there is a nice tool on GitHub.
Synx is a command-line tool that reorganizes your Xcode project folder to match your Xcode groups.
Hope this helps somebody
看看 andyvn22 的答案 此处
解释一下:
并注意其名称下方的“Path:”设置。点击
“选择...”并将其设置为同名的新文件夹。
在它的名字下面。单击“无”旁边的图标(那是什么,一个文件
在窗口中?)并将其设置为同名的新文件夹。
然后,您需要手动将磁盘上的所有现有文件移动到新文件夹。
刚刚在我的 Xcode4 项目中尝试过这个,效果非常好。
Have a look at andyvn22's answer here
To paraphrase:
on it, and notice the "Path:" setting just below its name. Click
"Choose..." and set it to a new folder with the same name.
below its name. Click the icon next to "None" (what is that, a file
in a window?) and set it to a new folder with the same name.
Then you'll need to move any existing files on disk to the new folder manually.
Just tried this in my Xcode4 project, works like a charm.