【发布时间】:2017-08-20 11:28:19
【问题描述】:
我试图在 WatchKit 上使用 segue 和上下文,我遇到了这个问题:
上下文类型“[Any]”不能与字典文字一起使用
这是我使用的代码:
override func contextsForSegue(withIdentifier segueIdentifier: String) -> [Any]? {
if segueIdentifier == "One" {
return ["sceneName" : "One"]
} else if segueIdentifier == "Two" {
return ["sceneName": "Two"]
} else {
return ["sceneName": "Three"]
}
}
在 segue 目的地有这段代码,不会产生错误:
@IBOutlet var theName: WKInterfaceLabel!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
self.setTitle("")
let dict = context as? NSDictionary
if dict != nil {
let segueContext = dict![["sceneName"]] as! String
theName.setText(segueContext)
}
}
希望有人能帮忙!
【问题讨论】: