0
votes

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
I think you should be using the actual name of the columnName instead of the "columnName" like this, if var lastModifiedTime = object?["updatedAt"] as? NSDateLarry Pickles
try that, and tell me the resultsLarry Pickles
I am using the actual column name, had put a dummy name as an example, please let me know if there are any other issues with my approach!rafavinu
lol, that's good!! I was gonna say, that was too easy, give me a minuteLarry Pickles
So, PFObjects have special values that hold the data in their values without the need to call it like you are doing;Larry Pickles

1 Answers

0
votes

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 {