I have a DataManager class that is responsible for fetching data and handing it over to the DatabaseManager, which in-turn will insert it into core data.
The method that exposes itself to the webservice is below
-(void)fetchDetailsForId:(NSString *)userId withFieldInformation:(NSString *)fieldInfo
{
if (SessionIsActive) {
[APIRequester startWithRequest:[NSString stringWithFormat:@"%@?%@",userId, fieldInfo]
completionHandler:^(APIConnectionManager *connection, id user, NSError *error) {
//This is where the results are returned and the API manages its own threads and returns the result lazily
}];
}
}
The above method is within the DataManager class. Now, a few methods in the same class call the above method to get data from the server. This fetched data is then forwarded to the DatabaseManager for inserting into core data. A sample of this is
-(void)fetchCurrentDataForLoggedInUser
{
NSData *fetchedData = [self fetchDetailsForId:loggedInId withFieldInformation:@"all"];
//the fetchedData is then forwarded to DatabaseManager
}
Now, since the web method (first method) gets the data in the background thread (managed by the API), the value of the "fetchedData" in the above method will be null since the web method exits before the API gets the relevant data.
Can someone tell me the most recommended way of handling a situation like this? I am not asking for sample code or anything, just the right direction should be enough. I am looking for a permanent solution than a hack or easy workaround.
Thank you