findObjectsInBackgroundWithBlock: obtiene datos de Parse, pero solo existen datos dentro del bloque
Hice la siguiente clase de prueba para probar a recuperar datos de Parse:
-(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...
}
Por la sección comentada dentro del código, cuando imprimoself.scoreDictionary
dentro del código, funciona bien, y veo mi diccionario completo a medida que se llena de manera incremental. Sin embargo, una vez que finaliza el bloque, cuando vuelvo a imprimir el diccionario, ahora está vacío. Revisé dos veces con los documentos de la API de consulta, pero todavía no estoy seguro de lo que estoy haciendo incorrectamente.