将文件移动到 Xcode 中的真实文件夹中

发布于 2024-10-07 09:55:06 字数 574 浏览 0 评论 0原文

当我开始我的项目时,我很高兴在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

禾厶谷欠 2024-10-14 09:55:06

2017 年的一种现代(而且非常简单!)方法(Xcode 6、7、8,有时是 9,因为它有时会自动执行):

如果您将一堆文件移动到一个新文件夹中并保留子层次结构,实际上比单独移动每个文件要容易得多:

  1. 在 Xcode 文件夹树中创建新组,然后按照您喜欢的方式将文件组织到其中。
  2. 在 Finder 中创建匹配的物理文件夹树,并将物理文件组织到其中以匹配您在步骤 1 中所做的操作。Xcode
  3. 中的所有引用现在都应该是红色的(没关系!)。
  4. 从身份和类型管理器中,选择 Xcode 中要重新定位的,然后单击信息窗格中的文件夹图标:

  5. 在 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:

  1. Create new groups in the Xcode folder tree and organize your files into them however you like.
  2. Create a matching physical folder tree in Finder and organize your physical files into them to match what you did in step 1.
  3. All the references in Xcode should now be red (that's OK!).
  4. 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:

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

燃情 2024-10-14 09:55:06

2017 年 6 月进一步编辑: Xcode 9 会自动执行此操作,无需特殊努力。这个答案和Brandon的仅适用于Xcode 8及更早版本。

2016 年 12 月编辑:布兰登的以下答案现在是一个更好的解决方案。早在 2010 年创建这个答案时,这是我能找到的唯一选择。我现在建议下面的布兰登的答案


事实证明,将文件移动到真正的文件夹中当然是可能的,尽管并不像应有的那么简单。

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

##过程

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

  1. 告诉 Xcode 您想要将文件放在哪里
  • 右键/按住 Control 键单击您要移动的文件或文件组我想移动并从出现的上下文菜单中选择获取信息。将出现组信息文件信息窗口。
  • 单击窗口最右侧路径区域中的选择按钮。出现一个对话框。
  • 导航到要将文件移动到的文件夹。如果需要,创建一个新文件夹。单击对话框右下角的选择按钮,然后关闭组信息/文件信息窗口。
  • 组中的文件名称将变成红色,表示 Xcode 无法在您指定的位置找到它们。
  1. 移动实际文件
  • 在 Finder(或 Git)中,将您在步骤 1 中选择的文件移动到您想要将其放入的实际文件夹中。
  • 切换回 Xcode。文件/组应该全部再次变黑。如果仍有红色,那么您错过了将某些内容移动到正确的文件夹的情况。

##尖端
在调整该项目中的约 300 个文件时,我学到了一些重要的事情:

  • 有些文件拒绝以这种方式移动;也就是说,当您导航到新目的地时,选择按钮将被禁用,新建文件夹按钮也是如此。尽管我不知道为什么会有所不同,但解决方案是首先使用 Xcode 将这些文件放入一个组中(右键/按住 Control 键单击这些文件并选择,然后给该组名称),然后将组移动到新位置。在 Finder 中实际移动文件后,您可以将它们从组中删除(通过将它们拖到新的父组/文件夹中并删除该组)。
  • 在完成多个文件的步骤 2 后,每隔几分钟停止并构建一次。该构建会告诉您到目前为止是否搞砸了任何事情,以便在造成太大损害之前更容易返回并修复它。
  • 如果文件无法移动到您想要的位置(我在移动 Classes 文件夹中早期创建的一些文件时遇到了麻烦),您只需将它们从旧位置拖出即可将查找器移动到桌面等方便的地方,在 Xcode 中删除对它们的引用,然后通过右键/按住 Control 键单击添加现有文件选项重新导入它们。
  • 如果您过去使用 Xcode 删除了对文件的引用,而没有将它们移至此项目中的垃圾箱,那么您会发现不必移动的文件只是坐在那里。请小心,不要做我所做的事情,混淆我正在移动的当前文件组和旧的、不再链接的文件的名称,坚持让 Xcode 导入它们,因为您认为它很密集。

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:

  1. Tell Xcode where you want the files to be:
  • 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.
  1. Move the actual files
  • In the Finder (or Git) move the files you selected in step 1 into the actual folders you want them in.
  • Switch back to Xcode. The files/groups should all have turned black again. If any are still red then you've missed moving something to the right folder.

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

  • 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.
冰雪梦之恋 2024-10-14 09:55:06

在 Xcode 5 或 Xcode 6 中:

  1. 创建映射到 Finder 中的组的文件夹
  2. 将文件移至 Finder 中的这些文件夹中
  3. 选择左侧 Xcode 侧栏中红色的每个文件
  4. 单击“显示”按钮/隐藏实用程序”以显示右侧边栏(见图)
  5. 在“身份和类型”中,单击小按钮并选择文件位置(见图)

在此处输入图像描述

干杯。

In Xcode 5 or Xcode 6:

  1. Create the folders that map to your Groups in Finder
  2. Move the files into those folders in Finder
  3. Select each file that is red in the Xcode sidebar on the left
  4. Click the button "Show/Hide Utilities" to reveal the right sidebar (see figure)
  5. In "Identity and Type", click the tiny button and select the file location (see figure)

enter image description here

Cheers.

感悟人生的甜 2024-10-14 09:55:06

我发现解决 XCode 令人震惊的设计的最可靠方法是在 Finder 中组织所有文件,原因有两个:

  1. 与 XCode 的 GUI 不同,Finder 不会犯“错误”
  2. 一旦在 Finder 中组织好内容,您就可以拖动/drop 整个 Finder 文件夹到 XCode 中,并且...它完全符合您的要求,毫不费力

即使在移动现有 XCode 文件时,执行以下操作也会更快:

  1. 在 Finder 中选择文件
  2. 在 Finder 中为它们创建一个文件夹
  3. 拖动/drop 它们到文件夹(自动移动它们)
  4. 将 Finder 文件夹拖/放到 Xcode 中(自动:创建 Xcode 文件夹,添加 Finder 文件夹中的每个文件)
  5. cmd-选择您现在在 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:

  1. Finder doesn't make "mistakes", unlike XCode's GUI
  2. Once things are organized in Finder, you can drag/drop entire Finder folders into XCode, and ... it does exactly what you wanted, with no effort

Even when moving existing XCode files around, it is quicker to do this:

  1. Select the files in Finder
  2. Create a folder in Finder for them
  3. Drag/drop them to the folder (automatically Moves them)
  4. Drag/drop the Finder folder into Xcode (automatically: creates the Xcode folder, adds every file in the Finder folder)
  5. cmd-select every "red" file you now see in Xcode (because you moved them) and hit the delete key

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 :)

浮云落日 2024-10-14 09:55:06

有一个易于设置和使用的命令行工具 - “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!

深爱成瘾 2024-10-14 09:55:06

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.

ゞ花落谁相伴 2024-10-14 09:55:06

我使用以下工具来实现它。以 Xcode 组组织文件夹

--no-default-exclusions

I used the following tool to achieve it.Organize Folders in Groups Xcode

--no-default-exclusions
温柔少女心 2024-10-14 09:55:06

我通常将文件直接移动到 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.

旧时光的容颜 2024-10-14 09:55:06

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

人事已非 2024-10-14 09:55:06

要在 xcode 4.5 中移动文件夹,我只需...

  1. 从 xcode 中删除文件/组并选择“删除引用”。
  2. 进入查找器并根据需要移动文件夹/文件。
  3. 完成后,我返回 Xcode 并选择 File->Add Files to {ProjectName}。
  4. 确保选中“将项目复制到目标组的文件夹(如果需要)” 确保选中
  5. “为任何添加的文件夹创建组”
  6. 确保为您的项目选中“添加到目标”

To move a folder in xcode 4.5 I just...

  1. Delete the files/groups from xcode and select "Remove Reference".
  2. Go into finder and move the folder/files as needed.
  3. Once done I go back into Xcode and choose File->Add Files to {ProjectName}.
  4. Make sure "Copy Items into Destination Group's folder (If needed)" is checked
  5. Make sure "Create Group for any added folder" is checked
  6. Make sure "Add to Target" is checked for your project
风铃鹿 2024-10-14 09:55:06

XCode 8 最简单的技术...

假设您在逻辑组中有文件 A、B、C,但希望将它们移动到硬盘驱动器上的文件夹中。

  1. 通过 Finder 创建目标文件夹
  2. 在 XCode 中添加文件夹(文件 -> 添加文件),使用选项窗格选择文件夹引用(不是组)
  3. 将文件 A、B、C 从(旧)组拖到(新) ) 项目导航器中的文件夹引用。 XCode 会将文件移动到项目中和磁盘上的文件夹中。

完毕。

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.

  1. Create a destination folder via Finder
  2. Add the folder in XCode (File -> Add Files ) using the Options pane to select a Folder Reference (not a group)
  3. Drag files A,B,C from the (old) group to the (new) folder reference in the project navigator. XCode will move the files into the folder, both in the the project, and on disk.

Done.

笔落惊风雨 2024-10-14 09:55:06

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文