1

I want to add UIlable that represent the time when post created I tried 3 different methods without any success

PS: Am using PFQueryTableViewController

Update :

 var dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = "MM-dd-yyyy HH:mm"
        var useDate = dateFormatter.stringFromDate
        cell.dateLabel.text = useDate

After above Code I get this error > can't assign of type NSDate -> string to type String? the error is points to cell.dateLabel.text = useDate

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject ? ) - > PFTableViewCell ? 
{
  let cell = tableView.dequeueReusableCellWithIdentifier("cellImg", forIndexPath: indexPath) as!MoreCell

  //Trial 1 
  cell.dateLabel.text = object ? .objectForKey(createdAt)

  //Trial 2
  cell.dateLabel.text = object ? .objectForKey("createdAt") as ? String

  //Trial 3
  cell.dateLabel.text = object ? .createdAt
 //Trial 4
  cell.dateLabel.text = object?.updatedAt >> Error Can't assign value of type NSDate to type string?

}
user3662992
  • 688
  • 1
  • 6
  • 16

1 Answers1

1

The error message is pretty self explanatory. The updatedAt token in Parse is a Date object, while you're trying to assign it to something that holds strings. So you need to change the date into a string before trying to set it for your text label.

EDIT:

You need to use your date formatter like this:

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy HH:mm"
let useDate = dateFormatter.stringFromDate(object["updatedAt"] as! NSDate)
cell.dateLabel.text = useDate
pbush25
  • 5,228
  • 2
  • 26
  • 35