I'm messing around with parsing JSON with SwiftyJSON on a swift playground. My code is as follows:
import UIKit
import SwiftyJSON
var partyList: [String] = []
var firstPresidentList: [String] = []
if let url = URL(string:"http://mysafeinfo.com/api/data?list=presidents&format=json") {
if let data = try? Data(contentsOf: url) {
let json = JSON(data: data)
for i in 1...43 {
let party = json[i]["pp"].stringValue
let president = json[i]["nm"].stringValue
if partyList.contains(party) {
print("\n")
} else {
partyList.append(party)
firstPresidentList.append(president)
}
}
print("All the different parties of U.S. presidents included "+partyList.joined(separator: ", ")+", in that order. The first presidents of those parties were (repectively) "+firstPresidentList.joined(separator: ", ")+".")
}
}
On the print line, I was wondering how I could join the arrays with a comma and space like I have, but add "and" before the last one.
Thank you!