在Xcode中的项目之间共享代码 [英] Share code between projects in Xcode

查看:63
本文介绍了在Xcode中的项目之间共享代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个通用应用程序,并且从该应用程序中,我使用不同的图像来制作不同的应用程序(相同的应用程序,不同的图像).

I made a generic app, and from that app, I use different images to make different apps (same app, different images).

到目前为止,我的想法一直是每次生成新应用程序时,我都复制代码并更改图像(有时需要一些代码行).但是,每次我在主应用程序中进行任何更改时,都必须在所有子应用程序中进行更改.

My idea until now has been every time I was generating a new app, I copied the code and changed the images (and sometimes some lines of code). But every time I change something in the main app, I have to change it in all the sub-apps.

我一直在考虑使用目标(每次创建一个新目标时,我都会使用一个新目标,并在该目标上链接了一个新的文件夹图像),但是我不确定这一点,因为我从未使用过之前是目标.

I've been thinking about using target for this (every time I create a new one, I use a new target with a new folder images linked to it), but I'm not sure about this as I never worked with targets before.

这是最好的方法吗?

如果是的话,最好的方法是什么?我在项目中创建了一个新目标,但它在其中创建了一个带有其自己的类的全新项目.

And if it is, how is the best way of doing it? I created a new target inside my project, but it creates a whole new project inside of it, with its owns classes.

推荐答案

对于您的情况,使用多个目标是一个很好的解决方案.对于每个目标,您将包括所有来源,并且仅包括该目标使用的图像(图像可以具有相同的名称,只需将它们放在单独的文件夹中即可).

For your case, using multiple targets is a good solution. For each target you'll include all sources, and only the images used by that target (images can have the same name, just put them in separate folders).

在Xcode 4上,您需要执行以下步骤:

On Xcode 4, you'd need to follow these steps:

  1. 转到项目"设置,右键单击您的主应用程序目标,然后选择复制".这已经包括来自主应用程序的相同来源.

  1. Go to Project settings, right click on your main app target and choose 'Duplicate'. This will already include same sources from the main app.

取消链接新目标中不需要的所有图像:

Unlink all images that you don't need in your new target:

  • 选择要取消链接的所有图像,然后在实用工具"面板(通常位于右侧)的文件检查器"部分中,取消选中新目标

创建一个新文件夹,在其中放置新目标/应用程序的图像,并将它们导入到项目中时,选择仅与新目标链接.

Create a new folder in which you place the images for your new target/app, and when you import them in the project, choose to link only with your new target.

当您复制目标时,它还将自动为新应用创建一个新的info.plist.您需要更改包ID,以及其他所需的选项.

When you duplicate your target, it will also automatically create a new info.plist for your new app. You'll need to change the bundle id, and any other options that you wish.

另一种选择是使主项目成为静态库,并且在所有其他项目中包括主项目,并链接目标.不会涉及到这一点,因为目标解决方案对于您的情况似乎更好,仅更改图像即可.

Another option would be to make the main project as a static library, and in all other projects include the main project, and link the target. Won't get into this, since the targets solution seems better for your case, for only changing the images.

这篇关于在Xcode中的项目之间共享代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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