如何使 Xcode 项目源文件与文件系统目录保持同步?

发布于 2024-08-22 03:39:02 字数 411 浏览 6 评论 0原文

我是 XCode 新手,我发现文件管理非常痛苦。在大多数 IDE 中,您可以简单地让项目源代码树引用磁盘上的目录结构。这使得向您的项目添加新文件变得很容易 - 您只需将它们放在磁盘上,它们就会自动编译。

使用 XCode,看来我必须创建文件并将其单独添加到项目中(或者被迫通过 UI 操作文件系统)。但这意味着通过源代码管理共享 .xcodeproj 充满了问题 - 通常,我们会在 xcodeproj 文件上遇到合并冲突 - 如果不这样做,我们经常会遇到链接器错误,因为在合并过程中某些文件项目中列出的内容将被删除。所以我必须将它们重新添加到项目文件中,直到我可以编译它,然后重新签入项目文件。

我确信我一定在这里遗漏了一些东西。我尝试使用“参考文件夹”,但其中的代码似乎没有被编译。构建一个 IDE,迫使每个人在向项目添加或删除文件时都必须修改单个共享文件,这似乎很疯狂。

I'm new to XCode and I find the file management a huge pain. In most IDEs, you can simply have the project source tree reference a directory structure on disk. This makes it easy to add new files to your project - you simply put them on disk, and they will get compiled automatically.

With XCode, it appears I have to both create the file and separately add it to the project (or be forced to manipulate the filesystem through the UI). But this means that sharing the .xcodeproj through source control is fraught with problems - often, we'll get merge conflicts on the xcodeproj file - and when we don't, we often get linker errors, because during the merge some of the files that were listed in the project get excised. So I have to go and re-add them to the project file until I can get it to compile, and then re-check in the project file.

I'm sure I must be missing something here. I tried using 'reference folders' but the code in them doesn't seem to get compiled. It seems insane to build an IDE that forces everyone to modify a single shared file whenever adding or removing files to a project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

北恋 2024-08-29 03:39:02

尽管有其他答案,但这绝对与其他 IDE 不同,并且是一个主要麻烦。据我所知没有好的解决方案。

我经常使用的一个技巧是:

  • 在项目树中选择一个目录,
  • 按删除键,
  • 选择“删除引用” ,尤其是对于其中包含大量文件的资源目录仅”,然后
  • 将该目录拖入项目中重新添加。

这会破坏任何对文件的手动重新排序,但它至少使同步操作成为 O(1) 操作,而不是更改文件数量的 O(n) 操作。

Other answers notwithstanding, this is absolutely a departure from other IDEs, and a major nuisance. There's no good solution I know of.

The one trick I use a lot to make it a little more bearable — especially with resource directories with lots of files in them — is:

  • select a directory in the project tree,
  • hit the delete key,
  • choose "Remove References Only", then
  • drag the directory into the project to re-add it.

This clobbers any manual reordering of files, but it does at least make syncing an O(1) operation, instead of being O(n) in the number of files changed.

不忘初心 2024-08-29 03:39:02

我很好奇您使用的是哪些 IDE 可以自动编译目录中的所有内容,因为我使用过的 IDE 都没有这样做(至少对于 C++ 而言)。我认为拥有一个包含所有文件列表的项目文件是相当标准的。通常,您可能只想包含针对不同目标的某些文件,具有每个文件的编译器设置等。

无论如何,考虑到这就是它的工作原理,您实际上不应该在合并中遇到太多问题冲突。最好的建议是尽早并经常做出承诺,这样您就不会与其他人的更改步调一致。仅将文件添加到项目中不会导致冲突,除非它们恰好添加到项目树中的同一位置。我们团队中使用 Xcode 已经很多年了,我们很少会遇到冲突:只有当有人重组了项目时才会发生冲突。

幸运的是,由于 Xcode 文件格式是文本,因此在发生冲突时通常很容易解决冲突,这与二进制格式的 Codewarrior 的糟糕旧时光不同。

I'm intrigued which IDEs you're using that automatically compile everything in a directory, as no IDE I've ever used does that (at least for C++). I think it's pretty standard to have a project file containing a list of all the files. Often you may want to only include certain files for different targets, have per-file compiler settings, etc.

Anyway, given that that's how it does work, you really shouldn't have too many problems from merge conflicts. The best advice would be commit early and often so that you don't get out of step with other people's changes. Merely adding files to the project shouldn't result in a conflict unless they happen to be added at exactly the same point in the project tree. We've been using Xcode in our team for years and we very rarely get conflicts: only if someone has restructured the project.

Fortunately, because the Xcode file format is text, it's generally quite easy to resolve conflicts when they occur, unlike the Bad Old Days of Codewarrior with it's binary format.

卸妝后依然美 2024-08-29 03:39:02

我使用的一种解决方法是通过按住 Ctrl 键并单击目录或项目,然后选择“将文件添加到...”名称,将文件手动添加到项目中。然后我手动选择未出现的文件。此外,如果需要,我会在选择屏幕显示上添加复制文件。希望这有帮助。

One work around that I use is to manually add the files to the project via the Ctrl+Click to the directory or project and select the Add Files to ... designation. Then I manually select the files that are not appearing. Additionally, I add the copy files if needed selection on the selection screen display. Hope this helps.

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