美文网首页
Swift4中[String:Any]转[NSAttribute

Swift4中[String:Any]转[NSAttribute

作者: Distance先生 | 来源:发表于2018-05-23 17:55 被阅读0次

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

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

相关文章

网友评论

      本文标题:Swift4中[String:Any]转[NSAttribute

      本文链接:https://www.haomeiwen.com/subject/ybqdjftx.html