为什么在 Xcode 中,可以创建组,但不能创建真正的文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10368101/
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
Why in Xcode, Groups can be created, but not real folders?
提问by nonopolarity
When doing iOS programming, it is interesting that in Xcode (4.3.2), we can create groups, such as a group call Images
, and add files to it (either as a link or choose "Copy items into group's folder"). So it looks like a real folder in the navigator, and it even mentions "copy into ... group's folder", but in fact there is no folder. All added files are in the same location as the .m
and .h
files.
在进行 iOS 编程时,有趣的是在 Xcode (4.3.2) 中,我们可以创建组,例如 group call Images
,并向其中添加文件(作为链接或选择“将项目复制到组的文件夹中”)。所以它在导航器中看起来像一个真正的文件夹,甚至提到“复制到...组的文件夹”,但实际上没有文件夹。所有添加的文件都与.m
和.h
文件位于同一位置。
Why would we want Groups, but not real folder? Is there advantage of Groups over the use of a folder?
为什么我们需要组,而不是真正的文件夹?组比使用文件夹有优势吗?
采纳答案by Hyman Lawrence
Note: In Xcode 10, the default behavior now creates a linked folder when you create a new group. The information below still applies otherwise.
注意:在 Xcode 10 中,默认行为现在会在您创建新组时创建一个链接文件夹。以下信息在其他情况下仍然适用。
The recommended way to organize files is via groups, because it's more flexible than creating directories, and allows you to create complex file hierarchies while maintaining a totally different file hierarchy on the file system. It's simply an organization tool. That said, it is possible to turn groups into folder references, or create them initially as folder references.
推荐的文件组织方式是通过组,因为它比创建目录更灵活,并且允许您创建复杂的文件层次结构,同时在文件系统上维护完全不同的文件层次结构。它只是一个组织工具。也就是说,可以将组转换为文件夹引用,或者最初将它们创建为文件夹引用。
Furthermore, using groups instead of folder references gives you greater flexibility if you need to change where things are in the file system - say you have a common folder of code that you use in a bunch of different projects. Groups allow you to organize the files inside of projects as if they were in the projects, while still maintaining one copy of the code in a central location. And yes, you can do this with folder references as well, but groups are much more flexible if you later want to add other things to the same group but don't want them to be added to that common folder.
此外,如果您需要更改文件系统中的内容,使用组而不是文件夹引用可以为您提供更大的灵活性 - 假设您有一个在一堆不同项目中使用的公共代码文件夹。组允许您组织项目内部的文件,就像它们在项目中一样,同时仍然在中央位置保留一份代码副本。是的,您也可以使用文件夹引用来执行此操作,但是如果您以后想要将其他内容添加到同一组但不希望将它们添加到该公共文件夹中,则组会更加灵活。
If you want to link a group to a folder, click on the group in the project file tree and hit command+option+1. Below the drop down that'll say something like "Path: Relative to Group" on the right, there's a little white square with a grey border around it kinda icon next to the word "none". Clicking on this and then selecting/creating a folder will bind the group to the folder.
如果要将组链接到文件夹,请单击项目文件树中的组并点击 command+option+1。在右侧的下拉菜单下方会显示类似“路径:相对于组”的内容,有一个白色的小方块,周围有灰色边框,有点像“无”一词旁边的图标。单击此按钮然后选择/创建文件夹会将组绑定到文件夹。
Furthermore, when you drag a folder into Xcode, it will ask you if you want it to be a group or a folder reference:
此外,当您将文件夹拖入 Xcode 时,它会询问您是希望它是一个组还是一个文件夹引用:
回答by Dave Wood
This is a pet peeve of mine.
这是我最讨厌的事情。
I recommend, making the folder in your file system, where you have your project files, then drag that folder into Xcode where you want the group. It will act like any other group, but now be linked to the folder on the file system. Adding files to that group in Xcode now adds them to the folder in the file system.
我建议,在你的文件系统中创建一个文件夹,在那里你有你的项目文件,然后将该文件夹拖到 Xcode 中你想要的组。它将像任何其他组一样工作,但现在链接到文件系统上的文件夹。在 Xcode 中将文件添加到该组现在会将它们添加到文件系统中的文件夹中。
Much cleaner way of working and helps when locating files in big projects. Keeps git cleaner too.
更简洁的工作方式,有助于在大型项目中定位文件。也让 git 更干净。
Update for Xcode 9:
Xcode 9 更新:
Once you have the groups in Xcode matching the directory structure on disk, moving a file from one group to another in Xcode will now move the file correctly on disk to match.
一旦您让 Xcode 中的组与磁盘上的目录结构匹配,在 Xcode 中将文件从一个组移动到另一个组现在将在磁盘上正确移动文件以匹配。
回答by Nitesh Borad
There is a Command Line Tool - "synx"available in github that do exactly what you need.
有一个命令行工具 -github 中提供的“synx”可以完全满足您的需求。
It reorganizes Xcode project folder in finder to match Xcode groups in project.
它重新组织了 finder 中的 Xcode 项目文件夹以匹配项目中的 Xcode 组。
You can find it here: https://github.com/venmo/synx
你可以在这里找到它:https: //github.com/venmo/synx
UPDATE: XCode 9 supports this feature by default. So, no need to use other tools anymore!
更新:XCode 9 默认支持此功能。所以,不再需要使用其他工具了!