(iOS 10, Swift 3) Reading `userInfo` dictionary from a CloudKit notification: How do I cast `[AnyHashable : Any]` to `[String : NSObject]`?

跟風遠走 提交于 2019-12-05 07:48:18

You just need to cast it first to NSDictionary and then you can cast it to [String: NSObject].

Try like this:

CKNotification(fromRemoteNotificationDictionary: userInfo as NSDictionary as! [String: NSObject])
NSString.localizedStringWithFormat("%@",(notification.userInfo as! [String: AnyObject] as! [String : NSObject])["theKeyValue"]!)

This is how I got the string. Feel free to correct it.

As suggested, it is enough to take away all casts and use userInfo as such for Swift 3 to handle the thing correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!