I asked another question similar to this one but I will try rewording it in order to make it clear exactly what it is I am trying to do. I currently have a JSON file that breaks down like so: There is a top level object, from that object there is an array of objects, each containing strings and ints. I want to get certain string values from these objects into an array that I can use to display in a UITableView and the only methods I see posted everywhere use this .append function, which is great when you are only checking the array to append one time maybe a few times a week but I would like the array to display the most current version every time the func is called.
So far I have tried many different methods in order to cast the Name string that is contained within each of the objects into an array by .appending an array in swift that I called NameList. Doing it this way causes the program to stall while it appends each of the names into the array. My last question got the recommendation of doing a plist instead but I think because I wasn't clear on exactly what problem I have been having was. So to sum it up again I just want to cast all the string values into an array that can be called by the tableview. Is there anyway to do this without appending the array each time and just have the strings from the json to go directly to the tableview? My current code is:
func updateArr() {
let path = NSBundle.mainBundle().pathForResource("CardList", ofType: "json")
let jsonData = NSData(contentsOfFile: path!, options: NSDataReadingOptions.DataReadingMappedIfSafe, error: nil)
let json = JSON(data: jsonData!)
for (key, subJson) in json["array"] {
if let Name = subJson["Name"].string {
if let Class = subJson["Class"].number {
if Class == Int(1) {
cardNameList.append(Name)
println(cardNameList)
}
}
}
}
}