Notifications Swift 3.0通知可转换为数组或字典数组?

Notifications Swift 3.0通知可转换为数组或字典数组?,notifications,swift3,hashable,Notifications,Swift3,Hashable,将此数据作为通知返回,并希望将其读入可用的变量类型。我让他们都去工作了,但报酬和aps除外 %@ [AnyHashable("description"): Open 10 common chests., AnyHashable("icon"): localhost:8000//media/achievements/Common%20Chest%20Go- Getter/bomb.jpg, AnyHashable("name"): Common Chest Go-Ge

将此数据作为通知返回,并希望将其读入可用的变量类型。我让他们都去工作了,但报酬和aps除外

    %@ [AnyHashable("description"): Open 10 common chests.,     AnyHashable("icon"):     localhost:8000//media/achievements/Common%20Chest%20Go-    Getter/bomb.jpg, AnyHashable("name"): Common Chest Go-Getter,     AnyHashable("gcm.message_id"):1486597426811663%bf6da727bf.   6da727, AnyHashable("rewards"): {"Battle helm":1,"Gems":1000}, AnyHashable("aps"): {
    alert = "Achievement Completed";
}]
那么如何将其转换为可用的变量呢

    AnyHashable("rewards"): {"Battle helm":1,"Gems":1000},     AnyHashable("aps"): {
    alert = "Achievement Completed";
}
返回的项目称为userInfo,类似于

let rewards = userInfo["rewards"] as! [String:Int] 
不起作用,任何帮助都将不胜感激!同样,我使用的是swift 3.0,因此swift 3.0示例可能会有所帮助

通知userInfo被解析为字典或[String:Any]

看起来您对此感到困惑:

let arrayOfStrings = [String]()
let dictionary = [String: Any]()

let arrayOfDictionaries = [[String:Any]]()
if let rewards = userInfo["rewards"] as? [String: Any] {

  if let battle = rewards["Battle helm"] as? Int {
    print(battle) // 1
  }

  if let gems = rewards["Gems"] as? Int {
    print(gems) // 1000
  }

}

if let aps = userInfo["aps"] as? [String: Any] {

  if let alert = aps["alert"] as? String {
    print(alert) // Achievement Completed
  }

}
let arrayOfStrings = [String]()
let dictionary = [String: Any]()

let arrayOfDictionaries = [[String:Any]]()