ios - Cant get array PFQuery objects from parse code block -
i dont know deal parse reason wont allow me save retrieved array mutable array created. works inside parse code block once outside, displays null. please?
pfquery *query = [pfquery querywithclassname:@"comments"]; [query wherekey:@"flirtid" equalto:recipe.flirtid]; [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (!error) { comments = [[nsmutablearray alloc]initwitharray:objects]; // found objects (pfobject *object in objects) { } } else { // log details of failure nslog(@"error: %@ %@", error, [error userinfo]); } }]; nslog(@"%@",[comments objectatindex:0]);
it's working should. should read on how blocks work.
edit: try reading apple's documentation
you're nslogging 'comments' before comments gets set. how work? see, query running in background, , take bit of time. it's running asynchronously. code outside block run immediately.
while code comes before, because it's asynchronous block, can , run whenever.
try this:
comments = [[nsmutablearray alloc]initwitharray:objects]; nslog(@"%@",[comments objectatindex:0]);
the important question is, want after query? looks want save comments, what? determine next.
Comments
Post a Comment