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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4414181/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:17:16  来源:igfitidea点击:

Moving Files into a Real Folder in Xcode

xcodemacosiosdirectory

提问by Matthew Frederick

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 中使用 Groups 而不是文字文件夹:因为我在 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. 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。不幸的是,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.

我错过了什么?如何说服 Xcode 让我像使用组一样使用文件夹?这里有一个有点类似问题的答案,但它实际上并没有解决我的问题,因为我正在处理现有文件。

采纳答案by Matthew Frederick

FURTHER EDITED JUNE 2017:Xcode 9 does this automatically, no special effort required. This answer and Brandon'sonly apply to Xcode 8 and earlier.

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

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.

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



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),但在此过程中学到了重要的东西。

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 Infofrom the contextual menu that appears. The Group Infoor File Infowindow appears.

    • Click the Choosebutton on the far right side of the window in the Patharea. A dialog box appears.

    • Navigate to the folder you want the files to be moved to. Create a New Folderif needed. Click the Choosebutton in the bottom-right corner of the dialog box, then close the Group Info/File Infowindow.

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

  2. 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.
  1. 告诉 Xcode 你想要文件的位置

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

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

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

    • 该文件的名称/组中的文件会变成红色,表示的Xcode不能在你指定的地方找到他们。

  2. 移动实际文件

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

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

Tips

提示

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

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

  • Some files refuse to move this way; that is, when you navigate to the new destination the Choosebutton is disabled, as is the New Folderbutton. 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 Filesoption.

  • 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.
  • 有些文件拒绝以这种方式移动;也就是说,当您导航到新目标时,“选择”按钮和“新建文件夹按钮将被禁用。该解决方案,但我不知道为什么它的确与众不同,是第一次使用Xcode中把这些文件放在一个组(右/控制单击该文件,并选择,并给该组的名称),然后移动组到新位置。在 Finder 中实际移动文件后,您可以将它们从组中删除(通过将它们拖到新的父组/文件夹中并删除该组)。

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

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

  • 如果过去您曾使用 Xcode 删除对文件的引用,而没有将它们移到此项目中的垃圾箱中,您会发现不必移动的文件只是坐在那里。注意不要像我做的那样,混淆我正在移动的当前文件组的名称和较旧的、不再链接的文件,坚持让 Xcode 导入它们,因为你认为它很密集。

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

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

回答by brandonscript

A modern (and dead simple!) approach for 2017 (Xcode 6, 7, 8, and sometimes 9, since it does it automagically some of the time):

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

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 Groupin 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. Allthe files inside that group will now be automagically rediscovered!

  1. 在 Xcode 文件夹树中创建新组,然后根据需要将文件组织到它们中。
  2. 在 Finder 中创建匹配的物理文件夹树,并将您的物理文件组织到其中以匹配您在步骤 1 中所做的操作。
  3. Xcode 中的所有引用现在都应该是红色的(没关系!)。
  4. 从身份和类型管理器,选择集团在Xcode要搬迁,然后从信息窗格中的文件夹图标:

  5. 在 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 个步骤一次(这比单独重新定位每个文件更重要!)

Bonus Points!

奖励积分!

Say you accidentally screwed up the move and now a bunch of your files are red and can't be found: select multiplefiles 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 截图中的相同文件夹图标,找到包含这些文件的正确文件夹文件,它们会自动解决丢失的路径。

回答by reinaldoluckman

In Xcode 5 or Xcode 6:

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

enter image description here

enter image description here

Cheers.

干杯。

回答by Adam

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 中组织所有文件,原因有两个:

  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
  1. Finder 不会犯“错误”,不像 XCode 的 GUI
  2. 一旦在 Finder 中组织了所有内容,您就可以将整个 Finder 文件夹拖放到 XCode 中,并且……它完全符合您的要求,毫不费力

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

即使移动现有的 XCode 文件,这样做也更快:

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

注意:我从不使用“创建带有子组的拖动文件夹”选项,因为在 XCode 3 中,这通常是无可救药的错误并且可能会损坏项目。Apple 显然(恕我直言)不会在内部使用此功能,否则它永远不会被允许有如此多的错误;如果 Apple 不使用某个东西,那么使用它通常也不安全——他们不擅长测试 :)

回答by Nitesh Borad

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 9supports this feature by default. So, no need to use other tools anymore!

更新: XCode 9默认支持此功能。所以,不再需要使用其他工具了!

回答by Guy Daher

Xcode 9

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 9 现在似乎默认支持它。当您将文件从一个组移动到另一个组时,文件也将从旧文件夹移动到新文件夹。这是在 WWDC 2017 中宣布的。

回答by Mike.R

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

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

--no-default-exclusions

回答by Xie Yanbo

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.

我通常将文件直接移动到 Finder 中的目录,然后在 XCode 的“获取信息”对话框中修复带有红色名称的文件:单击“选择...”按钮并选择文件的新位置。这是我想在 XCode 中移动文件时的第一个响应,它可以工作。

回答by Snowcrash

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.

从 Xcode 4.5 开始,当您拖入文件夹结构时,它会自动变成项目导航器中的嵌套组。然后,如果您在磁盘上查看(例如,右键单击并选择在 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.

我发现尝试修复旧项目中的问题只是一种痛苦。事实证明,删除这些文件并再次将它们拖入要容易得多。

回答by Shannon Cole

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

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

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