Reputation: 289
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!
Upvotes: 1
Views: 280
Reputation: 37290
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];
Upvotes: 2
Reputation: 62676
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);
}
}];
Upvotes: 0