如何让 Xcode 在磁盘上的文件夹结构中复制项目组结构?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/338652/
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
How do I get Xcode to replicate project group structure in the folder structure on disk?
提问by Lawrence Johnston
I have an Xcode project with the following group structure:
我有一个具有以下组结构的 Xcode 项目:
ProjectName/
Classes/
class1.h
class1.m
class2.h
class2.m
...
XMLDocs/
doc1.xml
doc2.xml
...
Resources/
Info.plist
MainMenu.xib
...
and so on and so forth.
等等等等。
I'd like this to be represented in the folder structure on the disk as well:
我希望这也能在磁盘上的文件夹结构中表示:
ProjectFolder/
Project.xcodeproj
Classes/
class1.h
class1.m
class2.h
class2.m
...
XMLDocs/
doc1.xml
doc2.xml
...
Resources/
Info.plist
MainMenu.xib
...
as opposed to the usual everything in the root project folder methodology.
与根项目文件夹方法中通常的所有内容相反。
Is there any way to do this without manually creating the folder structure on the disk and then having to repoint all the reference in Xcode to the new location?
有没有办法做到这一点,而无需在磁盘上手动创建文件夹结构,然后必须将 Xcode 中的所有引用重新指向新位置?
Bonus points if you can tell me how to do this automatically any time I create a new group or add files to an existing group in Xcode.
每当我在 Xcode 中创建新组或将文件添加到现有组时,如果您能告诉我如何自动执行此操作,则可以加分。
采纳答案by Chris Hanson
There's no "make my disk look like my project structure" functionality in Xcode.
Xcode 中没有“让我的磁盘看起来像我的项目结构”功能。
You could automate the task using AppleScript, though: You can both examine and change project structure from a script. So you'd just have to write a script that iterates over the project structure and makes the folder hierarchy look the way the project structure does, and adjust where Xcode's file and group references point at the same time.
不过,您可以使用 AppleScript 自动执行任务:您可以通过脚本检查和更改项目结构。因此,您只需编写一个脚本来遍历项目结构并使文件夹层次结构看起来像项目结构那样,并同时调整 Xcode 的文件和组引用指向的位置。
回答by andyvn22
You cando this to some extent! There's just one extra step to do every time you create a new group (and this first time you'll have a lot of catching up to do!):
你可以在某种程度上做到这一点!每次创建新组时只需执行一个额外的步骤(这是第一次您有很多事情要做!):
Whenever you create a group in Xcode, immediately select it and open the righthand sidebar. Notice the "Location:" setting just below its name. Click the folder icon next to "None" and set it to a new folder with the same name.
每当您在 Xcode 中创建一个组时,立即选择它并打开右侧边栏。请注意其名称下方的“位置:”设置。单击“无”旁边的文件夹图标并将其设置为具有相同名称的新文件夹。
Now, whenever you add files to the group, they'll head to the corresponding folder on disk. Woo!
现在,无论何时向组中添加文件,它们都会转到磁盘上的相应文件夹。哇!
Unfortunately, this initial time, you'll have a lot of file-moving to do. (As you change the group paths, your files will all turn red, as Xcode will begin looking for them in the new folder. You'll have to manually move them from the Finder to fix it.) There is, however, a command-line tool to perform this initial migration for you: https://github.com/venmo/synx
不幸的是,在这个初始时间,您将有很多文件移动要做。(当您更改组路径时,您的文件将全部变为红色,因为 Xcode 将开始在新文件夹中查找它们。您必须手动将它们从 Finder 中移动以修复它。)但是,有一个命令-line 工具为您执行此初始迁移:https: //github.com/venmo/synx
回答by amrox
A folder reference is what you want. When dragging or adding files to the project there is an option to "Create Folder References for any added folders". Choose that and you'll get the behavior you want.
文件夹引用就是您想要的。将文件拖动或添加到项目时,可以选择“为任何添加的文件夹创建文件夹引用”。选择那个,你会得到你想要的行为。
alt text http://img.skitch.com/20081203-prtxsp7c36ern4afxxdixy93sq.png
替代文字 http://img.skitch.com/20081203-prtxsp7c36ern4afxxdixy93sq.png
You could try adding the entire enclosing folder of the project as a folder reference. That should get everything. Or add references for "Classes" "Resources" and "XML" individually.
您可以尝试将项目的整个封闭文件夹添加为文件夹引用。那应该得到一切。或者分别添加对“类”、“资源”和“XML”的引用。
回答by Adobels
Xcode9 solves this problem. By default, a new group is created with corresponding folder on disk.
Xcode9 解决了这个问题。默认情况下,使用磁盘上的相应文件夹创建一个新组。
回答by Wizard of Kneup
I found out that if you move files around in Xcode and press [CMD] at the same time then the folder structure will match the Xcode structure.
我发现如果您在 Xcode 中移动文件并同时按 [CMD],那么文件夹结构将与 Xcode 结构匹配。