1

I am trying to retrieve the updatedAt section of a parse object and displaying it as a label. I have created a date formatter yet when I convert it to a string it just becomes a null value. Here is the code:

- (void)viewDidLoad { 
[super viewDidLoad];

PFQuery *BizarroTime = [PFQuery queryWithClassName:@"Bizarro"];
[BizarroTime getObjectInBackgroundWithId:@"MkoIkCBMdP" block:^(PFObject *Bizarro, NSError *error) {
    NSDate *BizarroDate = Bizarro[@"updatedAt"];
    NSDateFormatter *df = [NSDateFormatter new];
    [df setDateFormat:@"MMMM dd 'at' HH:mm"];
    self.BizarroUpdatedAt.text = [df stringFromDate:BizarroDate];
}];
}

Any help with this would be awesome! Thanks!

11
  • Are you getting the proper NSDate back before you attempt to format it as a string? Commented Aug 4, 2014 at 0:26
  • I am not sure, all that I know is that the date in parse's data browser is 2014-08-03T18:15:35.648Z under the updatedAt column which has type 'Date' Commented Aug 4, 2014 at 0:28
  • Try printing the NSDate. Commented Aug 4, 2014 at 0:28
  • Not sure if it actually reaching the app, how should I check? Commented Aug 4, 2014 at 0:28
  • NSLog(@"%@", BizarroDate); Commented Aug 4, 2014 at 0:30

2 Answers 2

2

To make danh's message more concise for future answer-seekers, the updatedAt field of a Parse PFObject* object cannot be accessed as if it's a value in the object's dictionary, ex.:

object[@"updatedAt"];

But must instead be accessed using Parse's updatedAt method:

[object updatedAt];
Sign up to request clarification or add additional context in comments.

Comments

0

You should check that the returned object is non-nil. If there is an object, the way to get it's updated date is via the PFObject method called updatedAt ...

[BizarroTime getObjectInBackgroundWithId:@"MkoIkCBMdP" block:^(PFObject *Bizarro, NSError *error) {
    if (Bizarro) {
        NSDate *BizarroDate = [Bizarro updatedAt];
        // format as you have it
    } else {
        NSLog(@"%@", error);
    }
}];

1 Comment

That still returns nill

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.