I want to convert an array of users into a string of their names.
For example:
class User {
var name: String
init(name: String) {
self.name = name
}
}
let users = [
User(name: "John Smith"),
User(name: "Jane Doe"),
User(name: "Joe Bloggs")
]
Is this a good way to get the
String
:"John Smith, Jane Doe, Joe Bloggs"
?let usersNames = users.map({ $0.name }).joinWithSeparator(", ")
What if I want the last comma to be an ampersand? Is there a swift way to do that, or would I need to write my own method?