ios 如何创建一个不是应用程序但在其他项目中可见的 Xcode 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29868167/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 05:46:03  来源:igfitidea点击:

How to create an Xcode project that is not an app but is visible in other projects?

iosobjective-cxcode

提问by yonderboy

I want to create a project with a handful of categories that add useful functionality to UIKit. I want to keep this as a separate project so that it can be source-controlled separately (and eventually hosted on github, and downloadable as a dependency via cocoa pods...but let's skip this for now.)

我想创建一个包含少数类别的项目,为 UIKit 添加有用的功能。我想把它作为一个单独的项目,以便它可以单独进行源代码控制(并最终托管在 github 上,并且可以通过可可豆荚作为依赖项下载......但现在让我们跳过这个。)

But all the Xcode 6.1 project templates imply an app inside. When I select an empty project it complains about missing base SDK. But this cannot be set without a target present. It is quite confusing. I don't need a target. Do I? The project should be just a shell for a number of categories + a accompanying summary header file.

但是所有的 Xcode 6.1 项目模板都意味着里面有一个应用程序。当我选择一个空项目时,它会抱怨缺少基础 SDK。但是如果没有目标,就无法设置。这很令人困惑。我不需要目标。我吗?该项目应该只是多个类别的外壳 + 随附的摘要头文件。

I want to be able to drag this project as a subproject to any other proper app project, import the summary header file and expose those categories to the main project.

我希望能够将此项目作为子项目拖到任何其他适当的应用程序项目中,导入摘要头文件并将这些类别公开给主项目。

Any advice?

有什么建议吗?

回答by bbum

You need a target. Every source file that should be compiled must be a part of a target.

你需要一个目标。应该编译的每个源文件都必须是目标的一部分。

You could reference each source file from the target(s) in your app's Xcode projects, but that'd be tedious as you'd have to add to every project manually when you add source to your shared repository.

您可以从应用程序的 Xcode 项目中的目标引用每个源文件,但这会很乏味,因为在将源添加到共享存储库时必须手动添加到每个项目。

Either create an embedded framework project or a static library. Unless you are really going to share code between an app and an app's extension, go with the static library. It is a lot easier to manage.

创建嵌入式框架项目或静态库。除非您真的要在应用程序和应用程序的扩展程序之间共享代码,否则请使用静态库。管理起来要容易得多。

Create a project that has a static library target, add the files to that static library.

创建一个具有静态库目标的项目,将文件添加到该静态库中。

Then create a workspace that has your static library project and your app(s) project(s) in it. Modify the app targets to link against the static library.

然后创建一个工作区,其中包含您的静态库项目和您的应用程序项目。修改应用程序目标以链接到静态库。