This code has the JSON but no matter what I do I haven’t been able to figure out how to pass this JSON to an instance variable. Each time I set it to a variable and call that variable outside of this method its nil. So what I can gather is that the variable is called before the following async call returns.
So the question is what can I do to the following code so that I can extract the JSON value. Somewhere on the internet I read that I would need to pass it a block which would server as a call back on completion but I cannot figure out how to do that for the following code
//Gets the JSON object that contains the entries from the server
-(void)getEntriesFromServer
{
NSLog(@"%s", __PRETTY_FUNCTION__);
[[appAPIClient sharedClient] getPath:@"/entries"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id JSON)
{
NSLog(@" JSON array = %@",[JSON valueForKeyPath:@"entries"]);
}failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@" Json not received");
}];
}
Thanks
try to add
__blockto definition of an array e.g__block NSArray* entriesArray;or make a property like
and change your code like this
Hope it’ll help