使用Xcode 7(Beta 3)构建Swift框架以用作嵌入式二进制文件 [英] Building a Swift Framework with Xcode 7 (Beta 3) to use as an Embedded Binary

查看:133
本文介绍了使用Xcode 7(Beta 3)构建Swift框架以用作嵌入式二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自iOS 8引入嵌入式二进制文件以来,我一直希望将大量常用代码移植到框架中。我决定等一年才做到这一点,而今年,凭借Xcode 7 Beta和iOS 9,我就开始这么做了。

Ever since Embedded Binaries were introduced in iOS 8, I have been wanting to port a lot of my common code into frameworks. I decided to wait one year before doing it and this year, with Xcode 7 Beta and iOS 9, I'm starting to do that just that.

我已经开始了Xcode 7中的Cocoa Touch框架项目,我想将其编译成可用的框架。我可以把它编译成.framework,但是有一些问题;也就是说,框架似乎不可导入新项目(我将简要描述我为此所做的步骤)。因此,我不确定我的框架是否有任何可见符号。

I have started a Cocoa Touch framework project in Xcode 7 and I want to compile it into a usable framework. I can get it to compile my project into a .framework, but there's a few issues; namely, the framework doesn't appear to be importable into new projects (I will describe the steps I did for that shortly). Because of that, I'm not sure if my framework has any visible symbols.

这是我创建框架所做的:

This is what I have done to create the Framework:


  1. 创建我的框架作为Cocoa Touch框架。

  2. 去了我的目标的Build阶段,去了Headers,并添加了我的所有Swift文件到公共部分,希望能导出我的所有符号,而不必将它们标记为 public

  3. I试图将我的项目归档为框架。目前,看起来Xcode 7 Beta 3有一个错误(将在今天晚些时候报告),它会生成损坏的存档文件。出于这个原因,我无法从管理器窗口获取我的框架。为了解决这个问题,我将Xcode中的Run操作的模式从Debug更改为Release,构建它并从我的项目的中获取它生成的 .framework build / iphoneos-release 目录。这是一个快速测试,所以我不需要为模拟器生成的框架。

  1. Created my Framework as a Cocoa Touch Framework.
  2. Went to my target's Build Phases, went to Headers, and added all my Swift files to the "Public" section, in hopes that will export all my simbols without having to mark them as public.
  3. I tried to archive my project as a framework. Currently, it looks like Xcode 7 Beta 3 has a bug (going to report it later today) in which it generates corrupted archive files. For this reason I couldn't get my framework from the Organizer Window. To work around this, I changed the schema of the Run action in Xcode from Debug to Release, built it and grabbed it's generated .framework from my project's build/iphoneos-release directory. This was a quick test so I didn't need the frameworks generated for emulators.

这就是我尝试添加的内容新项目的框架:

And this is what I did to try to add the framework to a new project:


  1. 创建一个框架组(用于组织目的)并将框架拖到那里,选择是当它问我是否要将文件复制到我的项目目录时。

  2. 去了我的目标设置,从链接库中删除了我的框架(自动添加了它),添加了它改为嵌入式二进制文件。这再次将框架添加到链接库,所以我不得不从那里删除它两次。在链接库中保留框架会导致链接器错误(无法找到框架 - 不知道为什么,但我认为它与我的问题无关,我应该向Apple报告的内容),但是一旦你从那里删除它似乎将它添加到嵌入式二进制文件时编译正常。

  3. 试图在文件中导入我的框架。 Xcode抱怨没有这样的模块。

不幸的是,尽管嵌入式框架已经存在了大约一年,我找不到关于这个主题的文章。

Unfortunately, despite the fact that embedded frameworks have been around for around a year, I can't find much writing on the topic.

所以我的问题是:我是否正确地创建了框架,使我的框架/其他任何东西都失败了一个Xcode 7 Beta错误?或者是否有不同的过程来创建我想用作嵌入式二进制文件的框架?我应该提一下,我想让这个库开源,我想将一个简单的 .framework 文件分发给想要使用它的人会很整洁。

So my question is: Am I creating the framework correctly, making it possible that my framework/anything else is failing due to an Xcode 7 Beta bug? Or is there a different procedure to create a framework that I want to use as an Embedded Binary? I should probably mention that I want to make this library open source, and I think distributing a plain .framework file to the people who want to use it would be neat.

推荐答案

我在Xcode 7上遇到了同样的问题。
我通过编辑项目的构建设置解决了这个问题。其中包括框架)。

I Had the same issue on Xcode 7. I solved it by editing the build settings of the project (the one which includes the framework).

框架搜索路径字段设置为 $(PROJECT_DIR)或包含.framework文件的目录的路径,它应该帮助Xcode找到模块。

By setting the Framework Search Paths field to $(PROJECT_DIR) or to the path to the directory that contains the .framework file it should help Xcode finding the module.

这篇关于使用Xcode 7(Beta 3)构建Swift框架以用作嵌入式二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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