简体   繁体   English

iPhone通用应用程序资源包

[英]iPhone Generic bundle for application resources

Have developed an iPhone app which has two different functionality and it using same images and string in some areas in both the project. 已经开发了一个iPhone应用程序,该应用程序具有两个不同的功能,并且在两个项目的某些区域使用相同的图像和字符串。 Here I am using preprocessor macros which are differentiating it during compile time say for example project one and project two. 我在这里使用预处理器宏,这些宏在编译时将其区分出来,例如项目一和项目二。

Here my question is is there any way to pass the images and string in generic way. 在这里,我的问题是有什么方法可以通用方式传递图像和字符串。 I mean if I execute the application for project one means it should only take relevant app's images and string it should not bundled with another project ie project two's source. 我的意思是,如果我为一个项目执行该应用程序,则它仅应获取相关应用程序的图像,并且不应将其与其他项目(即,两个项目的源)捆绑在一起。

Any idea and suggestion will be greatly appreciated. 任何想法和建议将不胜感激。

Have a look at the screenshot of a project that has two targets: 看一下具有两个目标的项目的屏幕截图:

在此处输入图片说明

And at folder structure: 并在文件夹结构中:

在此处输入图片说明

You can put shared assets in the Shared folder and add them to both targets like SharedImage.png in the example. 您可以将共享资产放在Shared文件夹中,并将它们添加到SharedImage.png中的两个目标,例如SharedImage.png For assets that has two different versions, you can put each version on the appropriate folder ( Target A or Target B ) and use the same name for both versions. 对于具有两个不同版本的资产,可以将每个版本放在相应的文件夹( Target ATarget B )上,并对两个版本使用相同的名称。 For example, when adding the image MyImage.png to Target A , you simply have to check the box Target A like in the following screenshot: 例如,将图像MyImage.png添加到Target A ,只需选中复选框Target A如以下屏幕截图所示:

在此处输入图片说明

Now, it is easy to use the correct asset for each target and without using preprocessor macros. 现在,很容易为每个目标使用正确的资产,而无需使用预处理器宏。 For example, the following code will use the correct version of MyImage.png whether it is running in Target A or Target B 例如,以下代码将使用正确版本的MyImage.png无论它是在Target A还是Target B

UIImage *image = [UIImage imageNamed:@"MyImage.png"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM