如何使用XCode 6构建iOS框架 [英] How to build iOS framework with XCode 6

查看:114
本文介绍了如何使用XCode 6构建iOS框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道熟悉的教程就此而言框架XCode 6模板改变了游戏。

I know of familiar tutorials on this, but introduction of framework XCode 6 template has changed the game.

我已经看过 WWDC 2014视频关于构建现代框架,但它更多地讨论了构建扩展,框架和扩展。应用所有内部单个项目。它没有指定我使用它构建的框架是否可以在任何项目中真正重用。

I already watched WWDC 2014 video about building modern frameworks but it talks more about building extensions, framework & app all inside single project. It does not specify if the framework I make with it is truly reusable across any project.

我正在构建XCode 6方式的框架(File-> New Project-> Framework和Library-> Cocoa Touch Framework,但是当我在我的测试应用程序项目中导入它时(与框架项目分开) - 我不断收到各种错误。

I am building framework the XCode 6 way (File->New Project->Framework and Library->Cocoa Touch Framework), but when I import it inside my test app project (separate from framework project) - I keep getting various errors.

示例:在框架内包含非模块化标头,依此类推。

Example: Include of non-modular header inside framework, and so on.

我知道这不是它所说的,并且还有一些缺少的步骤无论我在做什么。 旧技巧可能适用于所有人,但我在XCode 6之后根本找不到要遵循的方法。

I know this is not what it says, and there are quite some missing steps in whatever I am doing. The older tricks may have worked for everyone, but I simply don't find which way to follow after XCode 6.

例如,有框架需要的某些文件夹结构,但XCode 6在构建它时不符合它。这样对吗?如果没有,我怎样才能改变XCode构建框架文件夹层次结构的方式?

For example, there is some folder structure that a framework needs, but XCode 6 doesn't comply to it while building it. Is it right? If not, how can I change the way the XCode builds framework folder hierarchy?

我是否回到旧学校或者我在XCode 6中搞砸了一些微小的东西我是我无法创建可重用的框架?

Do I go back to old school or am I screwing some tiny thing in XCode 6 that I am unable to create a reusable framework?

推荐答案

我不确定您是否正在尝试使用Objective-C构建框架或斯威夫特,因为你的问题没有说明。我遇到了你用Swift提到的错误,所以我会给你构建Swift框架的方法。

I am not sure if you are trying to build a framework with Objective-C or Swift as your question doesn't state it. I've encountered errors you are mentioning with Swift so I'll give you my method to build Swift frameworks.

我发现Objective-C的过程非常简单并且记录良好,所以我会跳过这个。

I found the process for Objective-C to be very straightforward and well documented, so I'll skip this.

至于Swift,还有一些事情需要考虑。首先,不支持Swift静态库,因此在将应用程序链接到库时,您必须专门使用框架(也称为动态库)。

As for Swift, there are a few things to consider. First, Swift static libraries are not supported, so you must exclusively use a framework (aka dynamic library) when linking an app to a library.

以下是步骤:


  1. 使用New创建框架> IOS项目>框架&库,选择Cocoa Touch Framework

  1. Create the Framework using New > Project under IOS > Framework & Library, select Cocoa Touch Framework

要避免ld:warning:找不到选项...,请在构建设置中找到库搜索路径目标并删除路径。

To avoid the "ld: warning: directory not found for option..." goto Library Search Paths in Build Settings for your target and delete the paths.

您不能将Objective-C与Swift混合使用,所以甚至不要考虑在代码中添加Swift-Header桥接文件。

You can't mix Objective-C with Swift so don't even consider adding the Swift-Header bridge file in your code.

在swift中有一些情况需要从未公开的框架中导入代码。我已成功使用框架内的模块映射来处理这些情况。

There are some cases in swift where you need to import code from unexposed Frameworks. I've successfully used the module-map inside the framework to deal with these case.

我还在Build Settings中选择CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES来解决'include框架模块内的非模块化头文件。这似乎有效

I also select CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES in the Build Settings to solve 'include of non-modular header inside framework module'. That seems to work

我确保生成的头文件被标记为Public(而不是Project)。点击该文件,您将在目标会员下的检查员中看到选择

I make sure that the header file that gets generated is marked as Public (not Project). Click on the file and you'll see the selection in the inspector under 'Target Membership'

您可能遇到构建时出现一些奇怪的错误消息。当代码无法正确编译时,Xcode倾向于报告链接器错误,从而导致链接器需要输出其二进制文件的文件丢失。有时XCode不会显示您正在编译的文件中的错误,您需要手动编译构建输出并返回到文件。在其他时候,您将遇到需要删除缓存的问题。这些问题我称之为XCode蓝调并不断处理它。我发现在构建库时更常出现这种类型的问题。其余的应该按预期工作。

You may run into some bizarre error messages when building. Xcode has a tendency to report linker errors when your code can't compile correctly resulting in missing files the linker needs to output its binaries. Sometimes XCode won't show the errors in the files you are compiling and you need to go manually on the build output and go back to the files. Some other time, you'll get a problem where you need to delete the cache. Those issues I call XCode blues and deal with it constantly. I found this type of problems happens more often when building libraries. The rest should work as expected.

这篇关于如何使用XCode 6构建iOS框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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