tôi đã lớp thử nghiệm sau đây để thử lấy dữ liệu từ Parse:findObjectsInBackgroundWithBlock: nhận dữ liệu từ màu Tây Nguyên, nhưng dữ liệu chỉ tồn tại bên trong các khối
-(void)retrieveDataFromParse
{
PFQuery *query = [PFQuery queryWithClassName:@"TestObject"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(!error){
for (PFObject *object in objects){
NSString *nameFromObject = [NSString stringWithFormat:@"%@", [object objectForKey:@"Name"]];
NSString *dateFromObject = [NSString stringWithFormat:@"%@", [object createdAt]];
NSString *scoreFromObject = [NSString stringWithFormat:@"%@", [object objectForKey:@"Score"]];
[self addNewScore:scoreFromObject andDate:dateFromObject forUserName:nameFromObject];
NSLog(@"The dictionary is %@", self.scoreDictionary); //<-- here it works printing out the whole dictionary
}
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
NSLog(@"The dictionary is %@", self.scoreDictionary); //<- but after the block is called, here the dictionary is again empty...
}
mỗi phần nhận xét bên trong mã, khi tôi in self.scoreDictionary
bên trong mã, nó hoạt động tốt, và tôi thấy toàn bộ từ điển của tôi vì nó dần dần được lấp đầy. Tuy nhiên, sau khi khối kết thúc, khi tôi in lại từ điển, nó bây giờ đã trống. Tôi đã kiểm tra lại bằng tài liệu API truy vấn, nhưng tôi vẫn không chắc chắn những gì tôi đang làm không chính xác.
Cảm ơn, đặc biệt là minh họa rất hữu ích cho thấy các chủ đề! – daspianist