我试图从类型为[anyhashable:any]的变量访问特定的值,但是在访问任何值时,我会收到一个错误。关于这个问题,我浏览过互联网,但没有得到任何具体的解决方案。那么有没有其他的方法来访问它们呢?请帮忙并提前感谢。
函数,在其中我得到一个错误
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
guard let aps = userInfo[AnyHashable("gcm.notification.data")],
let data = aps["filters"] as! String else {
return
}
print(aps)
completionHandler(UIBackgroundFetchResult.newData)
}
在打印用户信息时获取的数据
[AnyHashable("gcm.notification.data"): {"filters":"fjjnbbx zjbxzj","history":"dsfdxf","message":"value1","source":"message source"}]