I've been away from iOS and programming for a long time and getting back in to it and I'm lost on how best to handle blocks inside methods that return data back to another class.
I created a method to download some data from the internet.
-(NSArray*) getDataFromWeb
{
DataSync * dataS = [[DataSync alloc] init];
[dataS downloadData:@"Full"
successBlock:^(NSArray *dataArray)
{
NSLog(@"Data : %@", dataArray);
myDataArray = [dataArray copy];
}
errorBlock:^(NSError *error)
{
NSLog(@"ERROR: %@",error);
}];
return myDataArray;
}
Normally in the past I would have had a return statement returning the array. But because the block is off getting data on another thread the return will fire too early and the data wont have been retrieved and I just get a (null) back.
What is the recommended way to pass the data back to another class that is called this method after the block has finished it work and populated the array with data? Can I have two return states in each of the success or error section of the blocks?