设置 Xcode 项目以在自定义目录中添加新文件
我如何设置我的 Xcode 项目,以便它在 Classes 目录中创建新的类文件 (.h/.m) 并在 Interfaces 目录中创建新的接口文件 (.xib/.nib)?
默认情况下,Xcode 在根项目目录中添加新文件,我必须手动将这些文件放入 Classes 和 Interfaces 目录中。
编辑:
我指的是 Xcode 文件 >新文件...选项。我希望从 Xcode 项目创建的新文件自动移动到相应的目录,例如 .h/.m 文件在 Classes 目录中自动创建,.xib 在 Interfaces 目录等中自动创建。我的意思是物理目录,而不是 Xcode“团体”。
How can i setup my Xcode project so that it creates new class files (.h/.m) in Classes directory and new interface files (.xib/.nib) in Interfaces directory?
By default Xcode adds new files in the root project directory, and i have to manually put these into Classes and Interfaces directories.
Edit:
I'm referring to the Xcode File > New File... option. I want the new files created from the Xcode project to move automatically to corresponding directories e.g. .h/.m files get automatically created in Classes directory, and .xib get automatically created in Interfaces directory etc. And i mean physical directories, not Xcode "Groups".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您已经在 Xcode 项目中创建了一个名为
Classes
的组(文件夹)或类似的内容。选择它并执行 Command+I(或右键单击它并选择获取信息)。将“路径”选项更改为您想要创建文件的位置。请注意,它只会影响您在其上创建的文件。在其他地方创建它们然后将它们移动到该组不会将它们移动到目录中。
编辑以上答案适用于 Xcode 3。在 Xcode 5 中,您需要在项目导航器中选择逻辑组(第一个导航器选项卡,使用 ⌘1 将其调出) ),然后使用文件检查器检查它(第一个实用程序选项卡,使用 ⌥⌘1 将其调出)。可以通过单击“位置”下拉菜单下方的文件夹图标来更改所有新文件的默认物理文件夹。
I assume you've made a group (folder) called
Classes
, or something along these lines, inside your Xcode project. Select it and do Command+I (or right-click it and select Get Info). Change the "Path" option to the place where you want files to be created.Please note that it will only affect files you create on it. Creating them elsewhere then moving them to this group will not move them into the directory.
EDIT The above answer applies to Xcode 3. In Xcode 5, you would need to select the logical group in the Project Navigator (first navigator tab, bring it up with ⌘1) and then inspect it with the File Inspector (first utility tab, bring it up with ⌥⌘1). The default physical folder for all the new files can be changed by clicking the folder icon below the Location dropdown menu.
在 Xcode 5 中,它会自动选择磁盘上的默认文件夹来匹配侧边栏中某些文件夹的项目文件夹,并且可以手动建立此链接。
在我的项目中,我有
AppName
、AppNameTests
的侧边栏组,以及我自己创建的一个名为Shared Components
的侧边栏组。当我在侧边栏中选择AppName
组并创建一个类时,“保存”对话框会自动深入到顶级AppName
内的AppName
子目录。磁盘上的文件夹,并对AppNameTests
中创建的类执行相同的操作。尽管磁盘上有一个
Shared Components
文件夹,但我无法让 Xcode 通过我的自定义Shared Components
侧边栏组来模仿此行为,但我找到了如何强制它!Xcode 只需要知道磁盘上的文件夹就是我的侧边栏组的全部内容。为此,请执行以下操作:
现在,当我选择此侧边栏组并创建文件时,保存对话框在我拖入项目侧边栏的文件夹中启动!
编辑:我发现了 Xcode 在
project.pbxproj
文件中使用的键:如果您更改文件夹的名称<。 /code> 键到
path
,即path = "Shared Components";
这基本上就是当您将文件夹作为组引用添加到项目时 Xcode 所做的事情(您。如果您希望侧边栏
name
与磁盘上的path
不同,还可以同时使用name
和path
键>.)In Xcode 5, it auto-selects the default folder on disk to match to the project folder in the sidebar for certain folders, and it is possible to manually establish this linkage.
In my project, I have sidebar groups for
AppName
,AppNameTests
, and one I created myself calledShared Components
. When I select theAppName
group in the sidebar and create a class, the Save dialog automatically drills into theAppName
subdirectory inside the top-levelAppName
folder on disk, and does the same for classes created insideAppNameTests
.I was unable to get Xcode to mimic this behaviour with my custom
Shared Components
sidebar group, despite having aShared Components
folder on disk, but I figured out how to coerce it!Xcode simply needed to know that the on-disk folder was what my sidebar group was all about. To do that:
Now, when I select this sidebar group and create a file, the Save dialog starts in the folder I dragged into the project sidebar. Victory!
Edit: I discovered the keys that Xcode uses in the
project.pbxproj
file for this: if you change a folder'sname
key topath
, i.e.path = "Shared Components";
that's basically what Xcode is doing when you add a folder to the project as a group reference. (You can also use both
name
andpath
keys if you want the sidebarname
to be different than the on-diskpath
.)