组织 xcode 4.0 复制捆绑资源

发布于 2024-10-08 20:42:59 字数 227 浏览 4 评论 0原文

有没有一种简单的方法来组织 xcode 4.0 中的复制捆绑资源中的文件?我的项目有多个目标,每次添加文件时,大多数时候我都需要将它们添加到每个项目中。当我错误地忘记将资源复制到每个目标时,如果我有一种简单的方法来捕获自己(而不是仅仅查看捆绑包中的文件数量,这最终会导致每个项目都相同),那么这将有很大帮助)。

如果我可以在资源列表中创建文件夹,那就容易多了,但似乎我不能。至少如果我能自动按字母顺序排列它们可能会有所帮助。

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冰魂雪魄 2024-10-15 20:42:59

您要做的就是解析 .pbxproj 文件。 .pbxproj 中的所有链接文件和资源均通过其自己的 UUID 进行标识。因此,

  1. 获取 rootObject 的 UUID
  2. rootObject 获取目标 UUID 列表
  3. 对于每个目标,获取 Resource 的 UUID 列表,源代码框架。和
    查找所有三种资源类型的文件 UUID 列表
  4. 比较每个目标的资源列表。

一些提示,
项目文件的格式是这样的,rootObject引用其他对象。

{
    archiveVersion = 1;
    classes = {
    };
    objectVersion = 45;
    objects = {
         /* .... List of all objects are here .... */
        }
    rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}

从 rootObject 中,我们可以跟踪 targets 值。

/* 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 */

在项目文件的目标部分中,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;
        };

What you have to do is to parse .pbxproj file. All linked file and resources in .pbxproj are identified from their own UUID. So,

  1. Get the rootObject's UUID
  2. Get list of targets UUID from rootObjects
  3. For each target get the list of UUID for Resource, Source and Framework. And
    find the list of files UUID for all of the three resource types
  4. Compare the list of resources for each of the targets.

Some hints,
The format of the project file is like this, the rootObject refer to other objects.

{
    archiveVersion = 1;
    classes = {
    };
    objectVersion = 45;
    objects = {
         /* .... List of all objects are here .... */
        }
    rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}

From the rootObject we can follow the targets value.

/* 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, buildPhases contains the link to the copied bundle resources list and link.

    /* 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;
        };
來不及說愛妳 2024-10-15 20:42:59

(在 Xcode 3.2.x 上):您可以按字母顺序排列文件通过选择一个阶段,然后编辑->排序->按名字。
至于将它们分成“文件夹”——没有什么可以阻止您进行多个复制阶段!您甚至可以为每个项目指定一个描述性名称。

(on Xcode 3.2.x): You can alphabetize the files in 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.

月下凄凉 2024-10-15 20:42:59

不知道在这种情况下它是否有帮助,但在 Xcode 中,当您选择一个文件并获取其信息(命令-I)时,其中一个选项卡是“目标”。从那里,您可以选择想要文件成为其中一部分的所有目标。我相信对于非编译文件,它只是将文件添加到所选目标的复制捆绑资源阶段。

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).

请帮我爱他 2024-10-15 20:42:59

您的资源组中可以有文件夹。只需将真正的查找器文件夹拖到 xcode 中,然后选择“为添加的文件夹创建文件夹引用”,然后选择您要使用的所有目标。

这将创建一个动态文件夹引用,该引用将自动添加该文件夹中的所有文件,而无需每次都单独添加文件。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文