Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Background

I'm trying to load the userInfo dictionary from application:didReceiveRemoteNotification:userInfo:fetchCompletionHandler in my app delegate.

I then need to cast userInfo from [AnyHashable:Any] to [String:NSObject] so I can use it in CloudKit's CKNotification:fromRemoteNotificationDictionary.

Question

When I do:

let ui = userInfo as! [String : NSObject]

I get the error:

'[AnyHashable:Any]' is not convertible to '[String:NSObject]'

Is there a better way to convert userInfo to the appropriate type, or am I on a completely wrong track?

like image 835
Anthony C Avatar asked Aug 29 '16 21:08

Anthony C


1 Answers

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])
like image 127
Leo Dabus Avatar answered Nov 20 '22 07:11

Leo Dabus