Skip to content

Instantly share code, notes, and snippets.

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