ho fatto la seguente classe di test per provare il recupero dei dati da Parse:findObjectsInBackgroundWithBlock: ottiene i dati da analizzare, ma i dati esiste solo all'interno del blocco
-(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...
}
Per la sezione commentata all'interno del codice, quando stampo self.scoreDictionary
all'interno del codice, funziona bene, e vedo il mio intero dizionario man mano che viene riempito in modo incrementale. Tuttavia, al termine del blocco, quando stampo di nuovo il dizionario, ora è vuoto. Ho controllato due volte con i documenti API della query, ma non sono ancora sicuro di cosa sto facendo in modo errato.
Grazie, soprattutto per l'illustrazione molto utile che mostra i fili! – daspianist