ios - How can I access the array saved in the for loop? (objective c) -


-(void) queryrestuarantsname {  nsmutablearray* restaurantnamearray = [[nsmutablearray alloc] init];  pfquery *query = [pfquery querywithclassname:@"menus"]; [query selectkeys: @[@"resturant", @"description", @"name"]]; query.limit = 1000000;  [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {           (pfobject *object in objects) {              nsstring* restaurant = [object objectforkey: @"resturant"];             [restaurantnamearray addobject:restaurant];          }     }];  } 

currently, outside of loop, restaurantnamearray said empty. however, in loop, has objects. how can access objects outside of loop?

it asynchronous code. access restaurantnamearray before receiving results findobjectsinbackgroundwithblock return empty results.

so processing of data in array should happen after findobjectsinbackgroundwithblock got results. expected following code work:

[self queryrestuarantsname]; [self.tableview reloaddata]; 

but not data not loaded moment. instead of reload data received response.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -