Dealing with some objC API, I receive an NSDictionary<NSString *, id> *>
which translates to [String : Any]
in Swift and which I was using for NSAttributedString.addAttributes:range:.
However, this method signature has now changed with Xcode 9 and now requires an [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)
}
How to convert a [String : Any]
to a [NSAttributedStringKey : Any]
?