Steve DeRienzo
Steve DeRienzo

Reputation: 237

accessing dictionary data from Parse and displaying on Tableview Cell

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

enter image description here

enter image description here

enter image description here

  //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

Answers (1)

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

Related Questions