将文件移动到 Xcode 中的真实文件夹中
当我开始我的项目时,我很高兴在 Xcode 中使用组而不是文字文件夹:因为我使用 Xcode 中的浏览器来访问所有内容,所以内容组织得很好,我很高兴。
然而,现在该项目即将共享以进行版本控制,对于那些试图通过终端扫描它的人来说,项目文件夹本身就是一场恐怖秀,大约有 300 个文件,其中一半以上是图形。
我现在正在尝试重新组织事物,创建真实的文件夹并将它们导入到 Xcode 中。不幸的是,Xcode 不允许我像处理组那样处理它们。例如,如果我右键单击实际添加的文件夹(蓝色,而不是黄色)并选择添加现有文件,它实际上不会将它们放入该文件夹中,而是将它们放入其根目录中。
同样,我无法将文件从人造文件夹(一组)移动到真实文件夹中:Xcode 不认为真实文件夹是将内容移动到的有效位置。
我缺少什么?如何说服 Xcode 让我以使用组的方式使用文件夹?这里有一个有点类似的问题的答案,但它实际上并没有解决我的问题,因为我正在处理现有文件。
When I started my project I was happy to use Groups in Xcode rather than literal folders: Since I'm using the browser in Xcode to access everything, stuff was nicely organized and I was happy.
However, now that the project is about to be shared for version control, the project folder itself is a horror show for those trying to scan it via a terminal, about 300 files, over half of which are graphics.
I'm trying to now reorganize things, creating real folders and importing them into Xcode. Unfortunately Xcode doesn't let me work with them the way it does with groups. For example, if I right-click on an actual added folder (blue, not yellow) and choose to add existing files, it doesn't actually put them in that folder, it puts them in its root.
Similarly, I can't move a file from a faux-folder (a group) into a real folder: Xcode doesn't consider the real folders to be valid places to move stuff to.
What am I missing? How can I convince Xcode to let me use the folders the way I use groups? There's an answer here to a somewhat similar question, but it doesn't actually solve my problem since I'm working with existing files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
2017 年的一种现代(而且非常简单!)方法(Xcode 6、7、8,有时是 9,因为它有时会自动执行):
如果您将一堆文件移动到一个新文件夹中并保留子层次结构,实际上比单独移动每个文件要容易得多:
从身份和类型管理器中,选择 Xcode 中要重新定位的组,然后单击信息窗格中的文件夹图标:
在 Finder 选择对话框中,找到您在步骤 2 中为此组创建的等效新文件夹。该组内的所有文件现在都将自动重新发现!
这不是很好吗?对于您创建的每个新组,您最多需要重复一次这 5 个步骤(这比单独重新定位每个文件要好!)
奖励积分!
假设您不小心搞砸了移动,现在一堆文件变成红色并且无法找到:选择多个损坏的文件,并在步骤 4 的屏幕截图中使用相同的文件夹图标,找到包含这些文件的正确文件夹,它们会自动解决丢失的路径。
A modern (and dead simple!) approach for 2017 (Xcode 6, 7, 8, and sometimes 9, since it does it automagically some of the time):
If you're moving a bunch of files into a new folder and are keeping the child hierarchy, it's actually a lot easier than moving each file individually:
From the Identity and Type manager, select the Group in Xcode that you want to relocate, then click the folder icon from the info pane:
In the Finder selection dialog, locate the equivalent new folder you created for this group in step 2. All the files inside that group will now be automagically rediscovered!
Isn't that nice? At most you'll have to repeat these 5 steps once for each new group you've created (which beats relocating each file individually!)
Bonus Points!
Say you accidentally screwed up the move and now a bunch of your files are red and can't be found: select multiple files that are broken, and using the same folder icon in the screenshot from step 4, find the correct folder that contains these files and they'll automatically resolve the missing paths.
2017 年 6 月进一步编辑: Xcode 9 会自动执行此操作,无需特殊努力。这个答案和Brandon的仅适用于Xcode 8及更早版本。
2016 年 12 月编辑:布兰登的以下答案现在是一个更好的解决方案。早在 2010 年创建这个答案时,这是我能找到的唯一选择。我现在建议下面的布兰登的答案。
事实证明,将文件移动到真正的文件夹中当然是可能的,尽管并不像应有的那么简单。
我从这里的一个问题中获得了基本信息,Xcode 组织文件和文件夹(核心数据模型对象 - iPhone),但一路上学到了重要的东西。
##过程
移动文件是一个包含多个子步骤的两步过程:
##尖端
在调整该项目中的约 300 个文件时,我学到了一些重要的事情:
FURTHER EDITED JUNE 2017: Xcode 9 does this automatically, no special effort required. This answer and Brandon's only apply to Xcode 8 and earlier.
EDITED DECEMBER 2016: Brandon's answer below is a better solution now. Back when this answer was created in 2010 this was the only option I could find. I now suggest Brandon's answer, below.
It turns out that moving files into real folders is certainly possible, though not as simple as it should be.
I got the basic information from a question here, Xcode organising files and folders (core data model objects - iPhone), but learned important things along the way.
##The Process
Moving the files is a two-step process with multiple sub-steps:
##Tips
I learned a couple of important things while adjusting the ~300 files in this project:
在 Xcode 5 或 Xcode 6 中:
干杯。
In Xcode 5 or Xcode 6:
Cheers.
我发现解决 XCode 令人震惊的设计的最可靠方法是在 Finder 中组织所有文件,原因有两个:
即使在移动现有 XCode 文件时,执行以下操作也会更快:
注意:我从不使用“创建带有子组的拖动文件夹”选项,因为在 XCode 3 中,这通常是无可救药的错误,并且可能会损坏项目。苹果显然(恕我直言)不会在内部使用这个功能,否则它永远不会被允许有如此多的错误;如果苹果不使用某个东西,那么使用它通常也不安全 - 他们不擅长测试:)
I've found the most reliable way to work around XCode's appalling design here is to organize ALL your files in Finder, for two reasons:
Even when moving existing XCode files around, it is quicker to do this:
NB: I never use the "create dragged folders with sub-groups" option, because in XCode 3 that was often hopelessly buggy and could corrupt projects. Apple clearly (IMHO) does NOT use this feature internally, otherwise it would never have been allowed to be so buggy; if Apple doesn't use a thing, it's generally not safe to use it either - they aren't good at testing :)
有一个易于设置和使用的命令行工具 - “synx”
可在 github 中找到,它完全可以满足此处的需要。
它会重新组织 Finder 中的 Xcode 项目文件夹以匹配项目中的 Xcode 组。
您可以在这里找到它:
https://github.com/venmo/synx
更新:
XCode 9 默认支持此功能。因此,无需再使用其他工具!
There is a simple to setup and use Command Line Tool - "synx"
available in github that do exactly what is needed here.
It reorganizes Xcode project folder in finder to match Xcode groups in project.
You can find it here:
https://github.com/venmo/synx
UPDATE:
XCode 9 supports this feature by default. So, no need to use other tools anymore!
Xcode 9
似乎 Xcode 9 现在默认支持它。当您将文件从一个组移动到另一个组时,文件也会从旧文件夹移动到新文件夹。这是在 WWDC 2017 上宣布的。
Xcode 9
It seems Xcode 9 now supports it by default. When you move files from a group to another, the file will also be moved from the old folder to the new folder. This was announced in WWDC 2017.
我使用以下工具来实现它。以 Xcode 组组织文件夹
I used the following tool to achieve it.Organize Folders in Groups Xcode
我通常将文件直接移动到 Finder 中的目录,然后在 XCode 的“获取信息”对话框中修复具有红色名称的文件:单击“选择...”按钮并选择文件的新位置。这是当我想在 XCode 中移动文件时的第一个响应,并且它有效。
I'm usually move files to the directory directly in the Finder, then fix the files with red-color names in XCode in their "Get Info" dialog: click the "Choose..." button and select file's new locatoin. That's the first response when I want to move files in XCode, and it works.
从 Xcode 4.5 开始,当您拖动文件夹结构时,它会自动转换为项目导航器中的嵌套组。然后,如果您查看磁盘(例如右键单击并选择在 Finder 中显示),文件夹结构将被保留。
我发现尝试修复旧项目中的问题非常痛苦。事实证明,删除这些文件并再次将它们拖入要容易得多。
As of Xcode 4.5 when you drag in a folder structure it is automatically turned into nested groups in the Project Navigator. Then, if you look on disk (e.g. right click and choose Show in Finder), the folder structure has been retained.
I found trying to fix things from an older project was just a pain. It turned out much easier to just delete these files and drag them in again.
要在 xcode 4.5 中移动文件夹,我只需...
To move a folder in xcode 4.5 I just...
XCode 8 最简单的技术...
假设您在逻辑组中有文件 A、B、C,但希望将它们移动到硬盘驱动器上的文件夹中。
完毕。
Easiest technique for XCode 8....
Assuming you have files A,B,C in a logical group, but want them moved into a folder on your hard drive.
Done.
在 XCode 11 上(我刚刚在 XCode 11.6 上验证了这一点),您可以在项目导航器下选择要移动的文件,右键单击所选文件,然后单击“从选择中新建组”。这将在磁盘上创建一个文件夹并适当地移动文件。
On XCode 11 (I just validated this on XCode 11.6), you can select the files you would like to move under the project navigator, right click on the selected files, and click "New Group From Selection". This will create a folder on disk and move the files appropriately.