Xcode项目资源组织和结构 [英] Xcode Project Resource Organization and Structure

查看:92
本文介绍了Xcode项目资源组织和结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们我对Xcode比较陌生,有一件困扰我的事情就是当我添加一个资源时,它会被添加到我项目目录的顶级目录中。因此,例如,目前,我的所有图像都位于顶级目录,这使得事情看起来很混乱。例如,我更愿意拥有一个 images / 文件夹,然后是其中的子文件夹来存储某些内容的图片,例如 tab-bar / 图标。这可能吗?或者只是将所有内容保存在顶级目录中?

Hey guys I'm relatively new to Xcode and one thing that has bothered me is that when I add a resource it gets added to the top level directory of my project directory. So for example, at the moment, all of my images are at the top level directory and it makes things look messy. I rather would've liked, for example, to have an images/ folder and then sub-folders within that to store images for certain things, like tab-bar/ icons. Is this possible? Or is it convention to just keep everything in the top level directory?

freenode的 #iphonedev 频道中有人告诉我一些关于构建过程规则的东西,它看起来太复杂了我认为我不应该打扰,并且考虑到解决方案的复杂性,大多数人只是将事情保存在他们的根目录中。也许它并不是那么复杂,我觉得它应该更容易。

Someone in the #iphonedev channel at freenode told me something about the build process rule or something, it just seemed too complicated I figured I shouldn't bother, and that most people just kept things at their root directory considering the complexity of the solution. Perhaps it isn't all that complicated though, I just felt it should be easier.

例如我也希望我的观点有一个子文件夹,比如 views / 存储我的所有nib文件;目前他们都在顶级目录。我的财产清单也是如此。

For example I would also like to have a sub-folder for my views, like views/ that stores all of my nib files; currently they are all in the top level directory. And the same goes for my property lists.

如果您能告诉我会议的内容,我将不胜感激,我怀疑只是将所有内容存储在最高级别目录。我指的是实际的文件系统,而不是简单地在Xcode中创建虚拟文件夹来组织事物,因为我的项目的顶级目录仍然是一团糟。如果可以更好地组织事情,我会很感激如何完成它的任何详细帮助。

I would appreciate it if you could tell me what the convention is, I doubt it is to just store everything in the top level directory. And I'm referring to the actual file system, not simply creating 'virtual folders' in Xcode to organize things, because the top level directory of my project will still be a mess. And if it is possible to organize things better, I would appreciate any detailed help on how to accomplish it.

我想我在最后的构建中听说过,整个文件结构被压缩到根目录。我对此并不介意,我只是希望在我开展项目时能够组织好事情。我认为这是构建规则的内容,但我不确定如何做或做什么。

I think I have heard that in the final build, the entire file structure gets squashed to the root directory. I don't mind so much about that, I just want things to be organized while I am working on my project. I think this is where that 'build rule' thing comes in, but I'm not sure how or what to do.

谢谢!

推荐答案

以下是格雷厄姆建议的更多解释:

Here's a little more explanation of Graham's suggestion:


  • 创建图像目录

  • 在Xcode中创建图像组

  • 右键单击该组并获取信息

  • 选择...将组的目录设置为图像目录

  • Create an images directory
  • Create an images Group in Xcode
  • Right-click the group and Get Info
  • "Choose..." to set the group's directory to be your images directory

现在,您放入图像组的任何内容都将自动生成进入images目录。如果您从Xcode,其他项目或Finder中拖放,或者通过右键单击images目录添加新...,则为true。 (这假设您在信息窗格中保留默认设置相对于组。)

Now, anything you put in the images group will automatically go into the images directory. That's true if you drag/drop from within Xcode, from other other projects or from Finder, or if you Add New... by right-clicking on the images directory. (This assumes you leave the default setting of "relative to group" in the info pane.)

这适用于您放入该组的任何内容(NIB等) 。

This will work for anything you put in that group (NIBs, etc).

对于 imageNamed:,您只需提供基本名称。

For imageNamed:, you just give the base name.

我的建议是保留少量的文件系统目录,并且主要使用Xcode中的组进行组织。但我同意,少数文件系统目录非常有用。我将所有源代码都放在了Classes目录中(只是因为Apple使用了这个名字;我会选择Sources或其他东西)。我还在顶层有一个Resources目录,通常在其下创建图像和音频目录。但是我通常不会创建很多真正的目录。这使事情变得更加整洁,但是使用shell更容易grep和通配。

My recommendation is to keep a small number of filesystem directories, and mostly organize with groups in Xcode. But I agree, a small number of filesystem directories are very helpful. I put all my source code in a Classes directory (just because Apple used that name; I would have picked "Sources" or something). I also have a Resources directory at the top level and generally create images and audio directories under that. But I don't generally create a lots of real directories beyond that. This keeps things a bit tidier, but makes it easier to grep and wildcard things with the shell.

除了shell工具之外,按组而不是目录组织的最大好处是对版本控制系统的影响,如颠覆。当您突然意识到您的视图组太大时,您可以重新组织它而不会受到移动文件的巨大影响。

Beyond shell tools, the big advantage of organizing by groups rather than directories is the impact on version control systems like subversion. When you suddenly realize that your "Views" group is way too big, you can reorganize it without taking the huge impact of moving files around.

这篇关于Xcode项目资源组织和结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆