【发布时间】:2018-03-12 16:38:23
【问题描述】:
处理一些 objC API,我收到一个 NSDictionary<NSString *, id> *>,它在 Swift 中转换为 [String : Any],我用于 NSAttributedString.addAttributes:range:。
但是,这个方法签名现在已经随 Xcode 9 更改,现在需要 [NSAttributedStringKey : Any]。
let attr: [String : Any]? = OldPodModule.getMyAttributes()
// Cannot assign value of type '[String : Any]?' to type '[NSAttributedStringKey : Any]?'
let newAttr: [NSAttributedStringKey : Any]? = attr
if let newAttr = newAttr {
myAttributedString.addAttributes(newAttr, range: range)
}
如何将[String : Any] 转换为[NSAttributedStringKey : Any]?
【问题讨论】:
标签: swift nsattributedstring swift4