Access date column in parse - Swift IoS development

111 views Asked by At

I am currently using the below mentioned code to access a date column in parse and display in my custom tableview controller.

if var x = object?["columnName"] as? String {
   cell.Name.text = x;
}

One of the columns is a date field. Hence i tried with

if var lastModifiedTime = object?["columnName"] as? NSDate {
    var dateFormat = NSDateFormatter()
    dateFormat.dateFormat = "EEE, MMM d, h:mm a"
    cell.LastModifiedTime.text = NSString(format: "%@", dateFormat.stringFromDate(lastModifiedTime)) as String;
}

But the var is taking no values. I have checked in parse and the column type is Date. Can anyone please tell where am i going wrong

1

There are 1 answers

1
Larry Pickles On

Check this out, this is in ObjC, but its basically the same as Swift for our purposes here:

PFObject * sh = [PFObject objectWithClassName:@"this"];
sh.createdAt
sh.updatedAt

You see, if you call to the dot notation of the PFObject, then you will get this values, there is no need to call it the way you are calling it

so, for you, it's like this, something like this:

if var lastModifiedTime = object .updatedAt NSDate {