如何让Xcode在磁盘上的文件夹结构中复制项目组结构?

时间:2023-01-13 12:08:03

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中的现有组时自动告诉我如何自动执行此操作,则可获得奖励积分。

4 个解决方案

#1


0  

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的文件和组引用同时指向的位置。

#2


58  

You can do 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!):

你可以在某种程度上做到这一点!每次创建一个新组时都只需要做一个额外的步骤(这是第一次你有很多事情要做!):

如何让Xcode在磁盘上的文件夹结构中复制项目组结构?

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

#3


11  

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”的引用。

#4


1  

Xcode9 solves this problem. By default, a new group is created with corresponding folder on disk.

Xcode9解决了这个问题。默认情况下,将在磁盘上创建具有相应文件夹的新组。

#1


0  

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的文件和组引用同时指向的位置。

#2


58  

You can do 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!):

你可以在某种程度上做到这一点!每次创建一个新组时都只需要做一个额外的步骤(这是第一次你有很多事情要做!):

如何让Xcode在磁盘上的文件夹结构中复制项目组结构?

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

#3


11  

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”的引用。

#4


1  

Xcode9 solves this problem. By default, a new group is created with corresponding folder on disk.

Xcode9解决了这个问题。默认情况下,将在磁盘上创建具有相应文件夹的新组。