首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Watch InterfaceController.swift中获取未解析的InterfaceController.swift标识符

在Watch InterfaceController.swift中获取未解析的InterfaceController.swift标识符
EN

Stack Overflow用户
提问于 2015-06-14 10:35:05
回答 1查看 1K关注 0票数 4

我的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,我有:

代码语言:javascript
复制
#import "MMWormhole.h"

在我的iPhone应用程序视图控制器中,我有以下内容:

代码语言:javascript
复制
import UIKit
import Foundation 

let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")

也没人抱怨。

但是,在我的手表接口控制器中,我有以下内容:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-22 01:12:46

这是我的答案。经过几天的挣扎和代码导师的帮助:

问题是:

代码语言:javascript
复制
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桥

  • 为iPhone应用程序和手表Ext添加应用程序组
  • 增加目标C
  • 目标都是
  • 构建设置:为iOS和Watch Ext设置相对路径中的*.h。设置*.h相对路径。例如../MMWormholeTest/MMWormholeTest/MMWormholeTest-Bridging-Header.h
  • 添加标题搜索路径:${PRODS_ROOT}/Headers,两个IOS 7监视Ext都是递归的

MMWormhole

  • 可可豆。
  • 为~>文件中的iOS和Watch Ext设置pod‘MMWorm空洞’、‘iOS 1.2.0’目标
  • 在桥接头文件中设置#import“MMWormhole.h”。
  • 在ViewController和InterfaceOController中,将worm孔设置为类作用域变量。沃尔虫洞:嗯虫洞!
  • 在MMWormhole中实例化ViewDidLoad,在WatchExt中实例化awakeWithContext,在awakeWithContext中设置侦听器,并由于闭包而使用self.lable.setText。例如self.label.setText(messageObject!就像!(串)
  • 不需要注册接收器,如堆栈溢出中的其他一些MMWormhole示例所示。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30828354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档