无法从Parse对象中检索updatedAt或createdAt值

时间:2013-08-25 03:57:33

标签: ios objective-c parse-platform

我是一位经验丰富的Android开发人员,试图使用Parse服务和sdk(https://www.parse.com/)来运行原型iOS应用。

很棒,我可以毫无困难地获得所有物品及其价值,一切正常。

但是,我无法获得Parse为每个对象自动创建的updatedAt值。
对我来说这是必须的,当数据就在那里时,我不想将一个附加的时间戳保存为字符串。

这是我正在做的事情的要点。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}  

// this works fine 
cell.textLabel.text = [object objectForKey:@"name"];

//substring however does not
NSDate *updated = [object objectForKey:@"updatedAt"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Lasted Updated: %@", [dateFormat stringFromDate:update]];

//i also tried like this at first
 cell.detailTextLabel.text = [NSString stringWithFormat:@"Lasted Updated: %@", [object objectForKey:@"updatedAt"]];

return cell;

}

3 个答案:

答案 0 :(得分:50)

傻马特。我想了一天,然后在我发布之后意识到我的错误。

updatedAt是所有PFObjects上的属性,无需使用密钥检索它。

给定一个名为object的PFObject ...

 NSDate *updated = [object updatedAt];
 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
 cell.detailTextLabel.text = [NSString stringWithFormat:@"Lasted Updated: %@", [dateFormat stringFromDate:updated]];

Working Date String

@Parse,帽子

答案 1 :(得分:15)

对于Swift:

let dateUpdated = object.updatedAt! as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "EEE, MMM d, h:mm a"
cell.updatedAtLabel.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated))

答案 2 :(得分:2)

我遇到了同样的问题,不使用objectForKey访问它,只需通过createdAt属性直接访问它。

在Swift中

object.createdAt

如文档中所述,密钥:

  

这不包括createdAt,updatedAt,authData或objectId。它   确实包含用户名和ACL等内容。