I have a data model/store object that interfaces with the Internet over several APIs containing data. The number of APIs to be interfaced with is dynamic: from a conceptual stan
I played around with dispatch groups the other day, here is a really helpful blog post by jrturton which should help you with the basics!
But basically it looks like your missing the line to enter/leave the dispatch group. So non of your runAPI
methods are being run as you have no items in the group and [[NSNotificationCenter defaultCenter] postNotificationName:@"apiDataUpdated" object:self];
gets called straight away.
dispatch_group_t group = dispatch_group_create();
for(MyAPIEndpoint __weak __block *ep in apiList)
{
dispatch_group_enter(group);
[self runAPI:ep withCompletionBlock:^(MyAPIEndpoint *api, NSError *err)
{
// update the data model here, code omitted as it's not relevant
dispatch_group_leave(group);
}];
}
});
dispatch_group_notify(group, dispatch_get_main_queue(),^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"apiDataUpdated" object:self];
});