2017-08-20 31 views
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) 
    } 
} 


希望有人能帮助!

回答

0

返回类型需要是一个对象数组,而您试图返回单个字典文本。

您尝试重写的函数用于将上下文发送到基于页面的接口控制器的数组。你确定,那是你想要做的?从你的代码看来,你应该重写函数contextForSegue(withIdentifier segueIdentifier: String) -> Any?

override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? { 

    if segueIdentifier == "One" { 
     return ["sceneName" : "One"] 
    } else if segueIdentifier == "Two" { 
     return ["sceneName": "Two"] 
    } else { 
     return ["sceneName": "Three"] 
    } 
}