Skip to content

Instantly share code, notes, and snippets.

@shakemno
Last active April 27, 2018 11:28
Show Gist options
  • Save shakemno/9d3593019a5aba3e683781504b9f7693 to your computer and use it in GitHub Desktop.
Save shakemno/9d3593019a5aba3e683781504b9f7693 to your computer and use it in GitHub Desktop.
NSAttributtedString get attribute value
func attributeValue<T>(_ key: NSAttributedStringKey) -> T? {
let attributes = self.attributes(at: 0, effectiveRange: nil)
guard attributes.keys.contains(key), let val = attributes[key] else {
return nil
}
return val as? T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment