Swift4中[String:Any]转[NSAttributedStringKey:Any]

通过扩展字典转类型。代码如下

extension Dictionary where Key == String{
    func toAttributedStringKeys() -> [NSAttributedStringKey: Value] {
        return Dictionary(uniqueKeysWithValues: map {
            key, value in (NSAttributedStringKey(key), value)
        })
    }
}

你可能感兴趣的:(Swift4中[String:Any]转[NSAttributedStringKey:Any])