I have a list of items in an array. The default output of the items is a simple list separated by commas. However, a proper sentence would include the word \"and\"
var arrNames:[String] = ["Apple","Bee","Carrot","Dog"];
var allNames:String!
override func viewDidLoad() {
super.viewDidLoad()
allNames = arrNames[0]
for i in 1...arrNames.count-1{
if i == arrNames.count - 1 {
allNames = allNames + " and " + arrNames[i]
}else{
allNames = allNames + ", " + arrNames[i]
}
}
print(allNames)
}