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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -