0
我試圖用賽格瑞與WatchKit背景下,我就遇到了這個問題:任何不能與字典文字使用
語境型「[任何]」不能用字典文字
使用
這裏是我使用的代碼:
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)
}
}
希望有人能幫助!