Skip to content

Instantly share code, notes, and snippets.

@ericdke
Last active January 22, 2016 20:11
Show Gist options
  • Select an option

  • Save ericdke/5b8aef3d08e8ea72cb2b to your computer and use it in GitHub Desktop.

Select an option

Save ericdke/5b8aef3d08e8ea72cb2b to your computer and use it in GitHub Desktop.
extension String {
var acronym:String {
let chSet = NSMutableCharacterSet.punctuationCharacterSet()
chSet.addCharactersInString("\n\r ")
let words = self.componentsSeparatedByCharactersInSet(chSet)
let letters = words.flatMap { $0.characters.first }.map { String($0) }
return letters.joinWithSeparator("").uppercaseString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment