iOS8:自定义 Swift 框架访问用 Objective-C 编写的外部框架

标签 ios8 frameworks xcode6 couchbase-lite

我正在尝试创建一个名为 CouchbaseKit 的自定义框架(Xcode 中的一个新目标)在 Swift 中。在我的CouchbaseKit ,我需要访问CouchBaseLite Framework完全写在 对象-C .我正在使用 Cocoapods管理CouchBaseLite和其他几个框架。下面是我的 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:

enter image description here

对于我的目标 我在构建阶段有以下设置。

定义模块是的

允许框架模块中的非模块化包含 是的

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

enter image description here

试过:
  • 由于该项目是在 Swift 中,我创建了一个 Objective-C 文件并点击“ 你想配置一个 Objective-C 桥接头吗?
  • 即使框架模块中的允许非模块化包含在所有目标中都设置为 YES,但当我尝试 #import <CouchbaseLite/CouchbaseLite.h> 时仍然出现错误。在 CouchbaseKit.h enter image description here

  • 这是我的自定义框架的构建阶段的样子 CouchbaseKit
    enter image description here

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

    最佳答案

    如果您仍然想使用 Cocoapods,可以关注 this

    脚步:

  • 创建一个名为您要使用的框架名称的文件夹
    那个案例CouchbaseLite并在其中创建模块图。文件名将是 module.map其内容为

  • 模块 CouchbaseLite {
    标题“../Pods/couchbase-lite-ios/CouchbaseLite.framework/Headers/CouchbaseLite.h”
    导出 *
    }
    Important Note: Don't add that folder to the project, I don't know why not when done it will not work .
  • Import Paths under Swift Compiler – Search Paths in your project settings。在模块路径中使用 ${SRCROOT}(例如 ${SRCROOT}/CouchbaseLite)
    .
  • 然后你可以像任何 swift 模块一样导入它。

  • 更新:
    它可以在 Xcode 中很好地工作,但是当我尝试使用 pod lint 验证 pod 时它仍然给出错误,我仍然不知道为什么。

    关于iOS8:自定义 Swift 框架访问用 Objective-C 编写的外部框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31688348/

    相关文章:

    objective-c - 向 XCode 4 添加框架

    ios - 如何使用 Objective C 将 UIObjects 从一个类重用到多个类?

    ios - 在没有导航 Controller Swift 的情况下以编程方式更改 View Controller

    swift - 从 iOS 8 框架加载图像

    位置权限的 iOS alertview 不会弹出

    iOS 8 UILabel 文本为空问题

    ios - CocoaPods with XCode 6.0.1 - 如何修复以红色显示的 Pods Frameworks?

    iphone - 如何在swift项目中传递值并在swift中访问自己创建的框架功能

    Java 验证框架

    ios - 是否可以在 Apple Watch 中创建图表?