I have a json object of this structure:
[
{
"id": 1,
"seat_no": 6
},
{
"id": 2,
"seat_no": 27
}
]
The main challenge is that I need to get the seat_no and add that to an int array which I will be using later on:
func getReserved() -> [Int] {
var reservedSeatsJSON : JSON = JSON()
var seats = Int()
var reservedSeats = [Int]()
for item in reservedSeatsJSON.array! {
seats = item["seat_no"].int!
reservedSeats.append(seats)
self.reservedSeatsLabel.text = "Reserved(\(reservedSeatsJSON.array!.count))"
}
return reservedSeats
}
Each time I run this, the reservedSeats returns empty. The main idea here is that I need to populate an int array in a for loop and return the populated array outside the for loop
reservedSeatsarray is empty?seatsin the loop. I think you'll be surprised by the output.