2014-07-06 53 views
0

从Parse查询类和关键字。最终的结果应该从arrayuserPostsObjects从PFQuerey中的数组获取最后一个对象

问题得到最后对象的关键textNSLog(@"FINAL OUTPUT %@", msgObject[@"text"]);返回整个数组中的关键text(上百个对象)不是最后目标

PFQuery *queryChatClass = [PFQuery queryWithClassName:@"Chat"]; 

[queryChatClass selectKeys:@[@"text", 
          @"user"]]; 

[queryChatClass findObjectsInBackgroundWithBlock:^(NSArray *userPostsObjects, NSError *error) { 
    if (!error) { 

     // Do something with the data 
     for (PFObject *msgObject in userPostsObjects) { 

      NSLog(@"FINAL OUTPUT %@", msgObject[@"text"]); 

     } 
    } 
    else { 

     // Log details of the failure 
     NSLog(@"Error: %@ %@", error, [error userInfo]); 
    } 
}]; 

我最好的猜测是使用for (PFObject *msgObject in [userPostsObjects lastObject])

然而这会导致:'NSInvalidArgumentException', reason: '-[PFObject countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x14567300'

回答

0

如果你使用lastObject,你可以“不用迭代”(你只有一个对象,而不是数组)。即:

NSLog(@"FINAL OUTPUT %@", [userPostsObjects lastObject][@"text"]); 
+0

谢谢你,现在有道理 – JSA986

相关问题