gpt4 book ai didi

notifications - (iOS 10,Swift 3)从 CloudKit 通知中读取 `userInfo` 字典 : How do I cast `[AnyHashable : Any]` to `[String : NSObject]` ?

转载 作者:行者123 更新时间:2023-12-04 07:38:29 25 4
gpt4 key购买 nike

背景

我正在尝试加载 userInfo来自 application:didReceiveRemoteNotification:userInfo:fetchCompletionHandler 的字典在我的应用程序委托(delegate)中。

然后我需要转换 userInfo来自 [AnyHashable:Any][String:NSObject]所以我可以在 CloudKit 的 CKNotification:fromRemoteNotificationDictionary 中使用它.

问题

当我做:

let ui = userInfo as! [String : NSObject]

我得到错误:
'[AnyHashable:Any]' is not convertible to '[String:NSObject]'

有没有更好的方法来转换 userInfo到适当的类型,还是我走错了路?

最佳答案

您只需先将其转换为 NSDictionary然后您可以将其转换为 [String: NSObject] .

试试这样:

CKNotification(fromRemoteNotificationDictionary: userInfo as NSDictionary as! [String: NSObject])

关于notifications - (iOS 10,Swift 3)从 CloudKit 通知中读取 `userInfo` 字典 : How do I cast `[AnyHashable : Any]` to `[String : NSObject]` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39215160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com