Reputation: 237
I have an object with dictionary properties I'm trying to access and display on a tableview cell. I haven't dealt with dictionary type data before, so displaying it has kind of confused me..
this is the object. Its from the class PoolAccount and the data i want to access is in the column "serviceHistory"
var poolHistory:PFObject = PFObject(className: "PoolAccount")
Print(poolHistory.valueForKey("serviceHistory")!.count!)
//returns this data
//How do i cast this data so i can use it in a tableview cell?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = ??
Upvotes: 2
Views: 508
Reputation: 112
I think you should change "serviceHistory" column type to Object. You can use NSDictionary
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
var data = poolHistory["serviceHistory"] as! NSArray
var element = data[indexPath.row] as! NSDictionary
var phValue = element["PH"] as! Int
cell.textLabel?.text = "\(phValue)"
}
Upvotes: 1