Skip to content

Instantly share code, notes, and snippets.

@steve228uk
Created July 25, 2016 21:02
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Comma List Swift
extension SequenceType where Generator.Element == String {
func commaList() -> String {
var result = joinWithSeparator(", ")
let range = result.rangeOfString(", ", options: .BackwardsSearch)
result.replaceRange(range!, with: " & ")
return result
}
}
["1", "2", "3", "4"].commaList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment