我的Apple Watch项目在Swift。我使用CocoaPods安装了MMWormhole,并创建了桥接头,如下所示:
http://bencoding.com/2015/04/15/adding-a-swift-bridge-header-manually/
How to call Objective-C code from Swift
当我创建桥接头时,我将其对准我的iphone应用程序,并查看扩展。
桥接头。h,我有:
#import "MMWormhole.h"在我的iPhone应用程序视图控制器中,我有以下内容:
import UIKit
import Foundation
let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")也没人抱怨。
但是,在我的手表接口控制器中,我有以下内容:
import WatchKit
import Foundation
...
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")
}它还抱怨“未解析标识符MMWormhole的使用”。
我甚至尝试使用#import "MMWormholeClient.h“,但是没有什么能解决这个问题。
我还尝试在创建桥接头时,只针对iphone。但还是..。不起作用。
我还在WatchExtension的podfile目标中创建了podfile目标中的podfile‘MMWorm空洞’、'~> 1.2.0‘。但仍未在MMWormhole interfaceController中识别
我漏掉了什么吗?
这是我的项目:https://www.dropbox.com/s/tsajeoopnghyl1g/MyTestCocoData.zip?dl=0
发布于 2015-06-22 01:12:46
这是我的答案。经过几天的挣扎和代码导师的帮助:
问题是:
1) The Objective-C bridge has to set the correct path and header search path so both IOS & WatchExt can use
2) The PodFile in MMWormhole must target for both iOS & WatchExt.
3) The code in MMWormhole npm page is not correct. Move the instantiation of MMWormhole out and be a class Variable.下面是一步一步的简短步骤:
目标C桥
MMWormhole
https://stackoverflow.com/questions/30828354
复制相似问题