There are already posts talking about this, but I am still not able to figure out my problem.
I am accessing my database and am converting the response into a JSON object - that part is working fine. Here is the code for that. joArray now has the data I need.
//Convert data to json object
let joArray : NSArray
do {
joArray = try JSONSerialization.jsonObject(with: data, options: []) as! NSArray
}
catch {
print(responseString)
print("error trying to convert data to JSON")
return
}
If I print out joArray . . .
print(joArray)
. . . this is what I get.
(
{
FirstName = Bob;
},
{
FirstName = Bill;
}
)
How can I put this data into a swift array so that it looks like this?
let FirstNameArray = ["Bob", "Bill"]
FirstName will always be in the same position, but there will be varying numbers of users (Bob, Bill, Mary, etc.).
(flat)mapthe array to your desired format. Side-note: Do not useNSArrayin Swift. You defeat the strong type system by throwing away the crucial type information. Use nativeArray