将文件移动到 Xcode 中的真实文件夹中 [英] Moving Files into a Real Folder in Xcode

查看:50
本文介绍了将文件移动到 Xcode 中的真实文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始我的项目时,我很高兴在 Xcode 中使用 Groups 而不是文字文件夹:因为我在 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.

然而,现在项目即将共享用于版本控制,项目文件夹本身对于那些试图通过终端扫描它的人来说是一场恐怖秀,大约有 300 个文件,其中一半以上是图形.

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.

我现在正在尝试重新组织内容,创建真正的文件夹并将它们导入 Xcode.不幸的是,Xcode 不允许我像处理组那样处理它们.例如,如果我右键单击实际添加的文件夹(蓝色,而不是黄色)并选择添加现有文件,它实际上并没有将它们放在该文件夹中,而是将它们放在其根目录中.

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.

同样,我无法将文件从虚假文件夹(一组)移动到真实文件夹中:Xcode 不认为真实文件夹是将内容移动到的有效位置.

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? 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.

推荐答案

2017 年 6 月进一步 Xcode 9 自动执行此操作,无需特别努力.此答案和 Brandon's 仅适用于 Xcode 8 及更早版本.

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.

2016 年 12 月Brandon 下面的回答现在是一个更好的解决方案.早在 2010 年创建此答案时,这是我能找到的唯一选项.我现在建议布兰登的回答,如下.

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.

我从这里的一个问题中获得了基本信息,Xcode 组织文件和文件夹(核心数据模型对象 - iPhone),但在此过程中学到了重要的东西.

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.

移动文件是一个包含多个子步骤的两步过程:

Moving the files is a two-step process with multiple sub-steps:

  1. 告诉 Xcode 您想要文件的位置:

  • 右键/按住 Control 键单击您要移动的文件或文件组,然后从出现的上下文菜单中选择获取信息.出现组信息文件信息窗口.

  • 点击路径区域窗口最右侧的选择按钮.出现一个对话框.

  • 导航到要将文件移动到的文件夹.如果需要,创建一个新文件夹.点击对话框右下角的选择按钮,然后关闭组信息/文件信息窗口.

  • 组中的文件名将变为红色,表示 Xcode 在您指定的位置找不到它们.

  • Right/Control-click on the file or file group that you'd like to move and choose Get Info from the contextual menu that appears. The Group Info or File Info window appears.

  • Click the Choose button on the far right side of the window in the Path area. A dialog box appears.

  • Navigate to the folder you want the files to be moved to. Create a New Folder if needed. Click the Choose button in the bottom-right corner of the dialog box, then close the Group Info/File Info window.

  • The names of the file/files in the group will turn red to indicate that Xcode can't find them in the place you specified.

移动实际文件

  • 在 Finder(或 Git)中,将您在步骤 1 中选择的文件移动到您想要它们所在的实际文件夹中.

  • 切换回 Xcode.文件/组都应该再次变黑.如果有任何内容仍然是红色的,那么您就没有将某些内容移到正确的文件夹中.

提示

在调整这个项目中的大约 300 个文件时,我学到了一些重要的东西:

Tips

I learned a couple of important things while adjusting the ~300 files in this project:

  • 有些文件拒绝以这种方式移动;也就是说,当您导航到新目标时,选择 按钮将被禁用,新建文件夹 按钮也是如此.解决方案,虽然我不知道为什么会有所不同,但首先使用 Xcode 将这些文件放在一个组中(右键/控制单击文件并选择 Group,然后给组名称),然后将该组移动到新位置.在 Finder 中实际移动文件后,您可以将它们从组中删除(通过将它们拖到新的父组/文件夹中并删除该组).

  • 在完成多个文件的第 2 步后,每隔几分钟停止并构建一次.构建会告诉您到目前为止是否搞砸了任何事情,以便在您造成太大损坏之前更轻松地返回并修复它.

  • 如果文件无法移动到您希望它们移动的位置—有一段时间,我在 Classes 文件夹中移动了一些早期创建的文件 - 真是太糟糕了.您可以简单地将它们从查找器中的旧位置拖到桌面等方便的地方,在 Xcode 中删除对它们的引用,然后通过右键/控制单击添加现有文件重新导入它们选项.

  • 如果过去您曾使用 Xcode 删除对文件的引用,但并未将它们移至此项目中的垃圾箱,您会发现无需移动的文件,只需坐在那里即可.小心不要像我做的那样,混淆我正在移动的当前文件组的名称和较旧的、不再链接的文件,坚持让 Xcode 导入它们,因为你认为它很密集.
  • Some files refuse to move this way; that is, when you navigate to the new destination the Choose button is disabled, as is the New Folder button. The solution, though I don't know why it makes a difference, is to first use Xcode to put those files in a Group (right/control-click the files and choose Group, and give the group a name) and then move the group to the new location. After you're actually moved the files in the Finder you can remove them from the group (by dragging them into the new parent group/folder and deleting the group).

  • Stop and build every few minutes, after completing step 2 for a number of files. The build will tell you if you've screwed anything up so far, making it easier to go back and fix it before you've done too much damage.

  • If the files won't move to where you want them to — I had a devil of a time moving some files that had been created early-on in the Classes folder — you can simply drag them out of their old place in the finder to someplace handy like the desktop, delete references to them in Xcode, and then re-import them via the right/control-click Add Existing Files option.

  • If in the past you've used Xcode to delete references to files without also moving them to the trash in this project, you'll find files that don't have to be moved but at just sitting there. Be careful that you don't do what I did, confusing the names of a current group of files I was moving and the older, no-longer-linked files, insisting that Xcode import them because you thought it was being dense.

希望这对一些未来的人有所帮助.我很惊讶它和以前一样困难,有时也很棘手.

Hope this helps some future person. I'm surprised that it was as difficult and occasionally tricky as it was.

这篇关于将文件移动到 Xcode 中的真实文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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