[英]Moving Files into a Real Folder in 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.当我开始我的项目时,我很高兴在 Xcode 中使用组而不是文字文件夹:因为我在 Xcode 中使用浏览器来访问所有内容,所以东西组织得很好,我很高兴。
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.然而,现在该项目即将共享以进行版本控制,对于那些试图通过终端扫描它的人来说,项目文件夹本身就是一场恐怖秀,大约 300 个文件,其中一半以上是图形。
I'm trying to now reorganize things, creating real folders and importing them into Xcode.我现在正在尝试重新组织事物,创建真正的文件夹并将它们导入 Xcode。 Unfortunately Xcode doesn't let me work with them the way it does with groups.不幸的是,Xcode 不允许我像处理组那样处理它们。 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.同样,我无法将文件从人造文件夹(一组)移动到真实文件夹中:Xcode 不认为真实文件夹是将内容移动到的有效位置。
What am I missing?我错过了什么? How can I convince Xcode to let me use the folders the way I use groups?我怎样才能说服 Xcode 让我像使用组一样使用文件夹? 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.这里有一个类似问题的答案,但它实际上并没有解决我的问题,因为我正在处理现有文件。
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: 从身份和类型管理器中,选择要重定位的Xcode中的组 ,然后单击信息窗格中的文件夹图标:
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! 在Finder选择对话框中,找到您在步骤2中为该组创建的等效新文件夹。该组中的所有文件现在将自动重新发现!
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!) 对于您创建的每个新组,最多只需要重复这5个步骤(这样可以单独重新定位每个文件!)
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. 假设您不小心搞砸了移动,现在一堆文件都是红色的,无法找到:选择多个已损坏的文件,并在步骤4的屏幕截图中使用相同的文件夹图标,找到包含这些文件的正确文件夹文件,他们将自动解决丢失的路径。
FURTHER EDITED JUNE 2017: Xcode 9 does this automatically, no special effort required. 2017年6月进一步编辑: Xcode 9自动执行此操作,无需特殊操作。 This answer and Brandon's only apply to Xcode 8 and earlier. 这个答案和Brandon仅适用于Xcode 8及更早版本。
EDITED DECEMBER 2016: Brandon's answer below is a better solution now. 2016年12月编辑: Brandon的答案现在是一个更好的解决方案。 Back when this answer was created in 2010 this was the only option I could find. 回到2010年创建这个答案时,这是我能找到的唯一选择。 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. 我从这里得到了一个问题的基本信息, Xcode组织文件和文件夹(核心数据模型对象 - iPhone) ,但在此过程中学到了重要的东西。
Moving the files is a two-step process with multiple sub-steps: 移动文件分为两步,包括多个子步骤:
Tell Xcode where you want the files to be : 告诉Xcode你想要文件的位置 :
Move the actual files 移动实际文件
I learned a couple of important things while adjusting the ~300 files in this project: 在调整此项目中的~300个文件时,我学到了几个重要的事情:
Hope this helps some future person. 希望这有助于未来的人。 I'm surprised that it was as difficult and occasionally tricky as it was. 令我感到惊讶的是,它既困难又偶尔也很棘手。
In Xcode 5 or Xcode 6: 在Xcode 5或Xcode 6中:
Cheers. 干杯。
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: 我发现解决XCode令人震惊的设计最可靠的方法是在Finder中整理所有文件,原因有两个:
Even when moving existing XCode files around, it is quicker to do this: 即使在移动现有的XCode文件时,也可以更快地执行此操作:
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. 注意:我从不使用“创建带有子组的拖动文件夹”选项,因为在XCode 3中,它通常是无可救药的错误并且可能损坏项目。 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 :) 如果Apple没有使用它,它通常也不安全使用它 - 它们不擅长测试:)
There is a simple to setup and use Command Line Tool - "synx" available in github that do exactly what is needed here. 有一个简单的设置和使用命令行工具 - 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. 更新: XCode 9默认支持此功能。 So, no need to use other tools anymore! 所以,不再需要使用其他工具了!
It seems Xcode 9 now supports it by default. 似乎Xcode 9现在默认支持它。 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. 这是在2017年WWDC上宣布的。
I used the following tool to achieve it. 我使用以下工具来实现它。 Organize Folders in Groups Xcode 组织组Xcode中的文件夹
--no-default-exclusions
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. 我通常直接在Finder中将文件移动到目录中,然后在“获取信息”对话框中修复XCode中带有红色名称的文件:单击“选择...”按钮并选择文件的新locatoin。 That's the first response when I want to move files in XCode, and it works. 这是我想在XCode中移动文件的第一个响应,它可以工作。
As of Xcode 4.5 when you drag in a folder structure it is automatically turned into nested groups in the Project Navigator. 从Xcode 4.5开始,当您在文件夹结构中拖动时,它会自动转换为Project Navigator中的嵌套组。 Then, if you look on disk (eg right click and choose Show in Finder), the folder structure has been retained. 然后,如果您在磁盘上查看(例如,右键单击并选择“在Finder中显示”),则保留文件夹结构。
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. 事实证明,删除这些文件并再次将它们拖入更容易。
To move a folder in xcode 4.5 I just... 要在xcode 4.5中移动文件夹我只是...
Easiest technique for XCode 8.... 最简单的XCode 8技术....
Assuming you have files A,B,C in a logical group, but want them moved into a folder on your hard drive. 假设您在逻辑组中有文件A,B,C,但希望将它们移动到硬盘驱动器上的文件夹中。
Done. 完成。
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".在 XCode 11 上(我刚刚在 XCode 11.6 上验证了这一点),您可以在项目导航器下选择要移动的文件,右键单击所选文件,然后单击“New Group From Selection”。 This will create a folder on disk and move the files appropriately.这将在磁盘上创建一个文件夹并适当地移动文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.