Last active
April 27, 2018 11:28
-
-
Save shakemno/9d3593019a5aba3e683781504b9f7693 to your computer and use it in GitHub Desktop.
NSAttributtedString get attribute value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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