Skip to content

Instantly share code, notes, and snippets.

@sketchytech
Created June 18, 2015 10:13
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 sketchytech/c5f64d9cde8907c79f08 to your computer and use it in GitHub Desktop.
Save sketchytech/c5f64d9cde8907c79f08 to your computer and use it in GitHub Desktop.
Functional NSAttributedString to NSAttributedString with added colour
typealias Attributer = NSAttributedString -> NSAttributedString
func color(color:UIColor) -> Attributer {
return {(aString:NSAttributedString) in
let mString = aString.mutableCopy()
mString.addAttribute(NSForegroundColorAttributeName, value: color, range: NSRange(location: 0, length: aString.length))
return mString.copy() as! NSAttributedString
}
}
let aString = NSAttributedString(string: "Hello Swift!")
let addColor = color(UIColor.brownColor())
addColor(aString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment