组织 xcode 4.0 复制捆绑资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4522922/
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
organizing xcode 4.0 copy bundle resources
提问by Joey
Is there an easy way to organize the files within the Copy Bundle Resources in xcode 4.0? I have multiple targets for my project, and every time I add files, I need to, most of the time, add them to every project. It would help a great deal if I had an easy way to catch myself when I mistakenly forget to copy resources to every target (other than just looking at the count of files in the bundle, which will eventually diverge from being the same for each project).
有没有一种简单的方法可以在 xcode 4.0 的 Copy Bundle Resources 中组织文件?我的项目有多个目标,每次添加文件时,大部分时间我都需要将它们添加到每个项目中。当我错误地忘记将资源复制到每个目标时,如果我有一种简单的方法来抓住自己,那将会有很大帮助(除了查看包中文件的数量,这最终会与每个项目的相同点不同) )。
It'd be a lot easier if I could make folders within the resources list, but it doesn't seem I can. At the very least it might help if I could automatically alphabetize them.
如果我可以在资源列表中创建文件夹会容易得多,但似乎我不能。至少,如果我可以自动按字母顺序排列它们可能会有所帮助。
回答by karim
What you have to do is to parse .pbxprojfile. All linked file and resources in .pbxprojare identified from their own UUID. So,
您需要做的是解析.pbxproj文件。.pbxproj中的所有链接文件和资源都从它们自己的UUID中识别出来。所以,
- Get the
rootObject
's UUID - Get list of targets UUID from
rootObject
s - For each target get the list of UUID for
Resource
,Source
andFramework
. And find the list of files UUID for all of the three resource types - Compare the list of resources for each of the targets.
- 获取
rootObject
的 UUID - 从
rootObject
s获取目标 UUID 列表 - 对于每个目标,获取
Resource
、Source
和的 UUID 列表Framework
。并找到所有三种资源类型的文件 UUID 列表 - 比较每个目标的资源列表。
Some hints, The format of the project file is like this, the rootObjectrefer to other objects.
一些提示,项目文件的格式是这样的,rootObject引用其他对象。
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* .... List of all objects are here .... */
}
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}
From the rootObject we can follow the targetsvalue.
从 rootObject 我们可以遵循目标值。
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MyProject" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
German,
de,
);
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
projectDirPath = "";
projectRoot = "";
targets = (
1D6058900D05DD3D006BFB54 /* TargetDebug */,
C446CDCB12BA35A1001324C8 /* TargetAdHoc */,
C446CF2D12BA3DDC001324C8 /* TargetAppStore */,
);
};
/* End PBXProject section */
In the target section of the project file, buildPhasescontains the link to the copied bundle resources list and link.
在项目文件的目标部分,buildPhases包含指向复制的包资源列表和链接的链接。
/* Begin PBXNativeTarget section */
1D6058900D05DD3D006BFB54 /* TargetAdHoc */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "TargetAdHoc" */;
buildPhases = (
1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = TargetAdHoc;
productName = MyProject;
productReference = 1D6058910D05DD3D006BFB54 /* MyProject.app */;
productType = "com.apple.product-type.application";
};
C446CDCC12BA35A1001324C8 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C446CDCD12BA35A1001324C8 /* MainWindow.xib in Resources */,
/* ....... list of all PNGs and XIB files..... */
81CDEBBF13B21B790067A088 /* AnImage.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
回答by Richard
(on Xcode 3.2.x): You can alphabetize the filesin a phase by selecting the phase, then Edit -> Sort -> By Name.
As far as breaking them up into "folders" -- nothing is stopping you from having multiple Copy phases! You can even give each one a descriptive name.
(在 Xcode 3.2.x 上):您可以通过选择阶段,然后编辑 -> 排序 -> 按名称来按字母顺序排列阶段中的文件。
至于将它们分解成“文件夹”——没有什么能阻止你拥有多个复制阶段!你甚至可以给每个人一个描述性的名字。
回答by Danny Parker
You can have folders in your Resources group. Just drag a real finder folder into xcode and choose 'Create folder references for added folders', and choose all the targets that you want to use.
您的资源组中可以有文件夹。只需将一个真正的 finder 文件夹拖到 xcode 中,然后选择“为添加的文件夹创建文件夹引用”,然后选择要使用的所有目标。
This will create a dynamic folder reference that will add all files within that folder automatically without you having to add the files individually everytime.
这将创建一个动态文件夹引用,该引用将自动添加该文件夹中的所有文件,而您不必每次都单独添加文件。
回答by mharper
Don't know if it's helpful in this instance, but in Xcode, when you select a file and Get Info on it (command-I), one of the tabs is "Targets." From there, you can select all the targets you want a file to be a part of. I believe that for non-compiled files, it merely adds the file to the Copy Bundle Resources phase of the selected target(s).
不知道它在这种情况下是否有帮助,但在 Xcode 中,当您选择一个文件并在其上获取信息(command-I)时,其中一个选项卡是“目标”。从那里,您可以选择希望文件成为其一部分的所有目标。我相信对于未编译的文件,它只是将文件添加到所选目标的复制捆绑资源阶段。