Skip to content

Instantly share code, notes, and snippets.

@AltiAntonov
Last active September 28, 2017 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AltiAntonov/f0f86e7cd04c61118e13f753191b5d9e to your computer and use it in GitHub Desktop.
Save AltiAntonov/f0f86e7cd04c61118e13f753191b5d9e to your computer and use it in GitHub Desktop.
Convert attributes [Stirng: Any] to Swift 4 attributes [NSAttributedStringKey: Any]
public extension Dictionary {
func toNSAttributedStringKeys() -> [NSAttributedStringKey: Any] {
var atts = [NSAttributedStringKey: Any]()
for key in keys {
if let keyString = key as? String {
atts[NSAttributedStringKey(keyString)] = self[key]
}
}
return atts
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment