iOS8:自定义Swift框架访问用Objective-C编写的外部框架 [英] iOS8: Custom Swift Framework accessing external framework written in Objective-C

查看:154
本文介绍了iOS8:自定义Swift框架访问用Objective-C编写的外部框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Swift中创建一个名为 CouchbaseKit (Xcode中的新目标)的自定义框架。在我的 CouchbaseKit 中,我需要访问完全用 Obj-C 编写的 CouchBaseLite Framework 。我正在使用 Cocoapods 来管理 CouchBaseLite 以及其他一些框架。下面是我的podfile。

I'm trying to create a custom framework called CouchbaseKit (a new target in Xcode) in Swift. Inside my CouchbaseKit, I need to access CouchBaseLite Framework that's entirely written in Obj-C. I'm using Cocoapods to manage CouchBaseLite and a couple of other frameworks. Below is my podfile.

Podfile

# Uncomment this line to define a global platform for your project
link_with ['CouchbaseKit']
# platform :ios, '8.0'

use_frameworks!
target 'CouchbaseDB' do
link_with ['CouchbaseKit']

pod 'couchbase-lite-ios'
pod 'SwiftyJSON', '~> 2.2.0'
pod 'Alamofire', '~> 1.2'
pod 'XCGLogger', '~> 2.0'
end

target 'CouchbaseDBTests' do
end

target 'CouchbaseKit' do
end

target 'CouchbaseKitTests' do
end

项目内的Pod:

对于我的 TARGETS ,我有以下内容构建阶段中的设置。

For my TARGETS I have the following settings in Build Phases.

定义模块

允许非-modular包含在框架模块中

问题:
当我尝试访问CouchbaseKit中的CouchbaseLite框架时(我的自定义框架),我收到一个错误,没有这样的模块'CouchbaseLite'不存在。

Problem: When I try to access the CouchbaseLite framework inside my CouchbaseKit (my custom framework), I get an error, "No such module 'CouchbaseLite' does not exist.

尝试:


  1. 由于该项目是在Swift中,我创建了一个Objective-C文件并点击是你想配置一个Objective-C桥接头吗?

尽管在所有目标中将框架模块中的允许非模块化包含设置为YES,但当我尝试 #import< CouchbaseLite / CouchbaseLite.h>时仍然会出错。 in CouchbaseKit.h

Even though Allow Non-modular Includes in Framework Modules is set to YES in all targets, I still get an error when I try to #import <CouchbaseLite/CouchbaseLite.h> in CouchbaseKit.h

以下是我的自定义框架的构建阶段 CouchbaseKit

Here is what my Build Phases looks like for my custom framework CouchbaseKit

问题:如何查看外部目标 - C fr我的自定义Swift框架中的amework(CouchasebaseLite)?

Question: How can I see an external Objective-C framework (CouchasebaseLite) in my custom Swift framework?

推荐答案

不幸的是Cocoapods 0.39遭受Transitive Vendor Dynamic Libraries Unsupported的困扰你将会最新的couchbase-lite-ios版本包括二进制CouchbaseLite.framework。不幸的是,这个问题让我非常困难,我不得不重构所有内容以使用Carthage,并在我的最终项目中手动管理我的框架。

Unfortunately Cocoapods 0.39 suffers from "Transitive Vendor Dynamic Libraries Unsupported" You'll see this with the newest couchbase-lite-ios release including the binary CouchbaseLite.framework. This unfortunately issue bit me so hard I had to refactor everything to use Carthage, and manually manage my frameworks in my final projects.

说到二进制发布的CouchbaseLite.framework只是缺少一个模块图。

Speaking of which the binary released CouchbaseLite.framework is simply missing a module map.

添加一个到:CouchbaseLite.framework / Modules / module.modulemap

Add one to: CouchbaseLite.framework/Modules/module.modulemap

framework module CouchbaseLite {
  umbrella header "CouchbaseLite.h"

  export *
  module * { export * }
}

然后,您将能够将此框架包含在桥接头中,并使您的动态框架正确嵌套。但你可能需要像我一样切换到使用Carthage构建你的CouchbaseKit.framework。

You will then be able to include this framework into a bridging header, and have your dynamic framework nest properly. But you might need to switch to building your CouchbaseKit.framework to using Carthage like I did.

这篇关于iOS8:自定义Swift框架访问用Objective-C编写的外部框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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