I have a custom class defined as such:
public class Location {
var name = String()
var address = String()
var place = String()
}
I'm then populating an Array using that class as follows:
var chosenLocation = [Location]()
var locationResult = Location()
//Code to parse data here//
for result in results! {
locationResult.name = result["name"] as String
locationResult.address = "Bogus Address"
locationResult.place = result["place"] as String
chosenLocation.append(locationResult)
}
This all seems to be working fine, but when I try to get the individual "name" value in cellForRowAtIndexPath I just get the last record over and over. I guess I just don't understand how to reference each entry since it's a class wrapped in an array. The code I believe is in question, and which is returning the same row over and over is:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"cell")
var locationAnswer = Location()
locationAnswer = chosenLocation[indexPath.row
cell.textLabel?.text = locationAnswer.name
return cell
}
I believe it's getting appended to chosenLocation correctly, but since I don't know how to "unwrap" it , a println only shows me that I have the correct number of values and not what's in them.
Thanks a bunch for any help you can provide!