Store and Web API Update


First, big thanks for writing this book. It’s been hugely helpful for me in learning iOS development.

I’m using the store style for an app. The store saves and loads the data from Core Data and serves it up to the controllers. But I also want to have the store pull updated data from a web API. I’m struggling to wrap my mind around how to call the web API in the store. You would need to use a delegate when calling the API, so you couldn’t just call the API in the fetchItemIfNecessary method could you? Currently I’ve got another method called fetchFromAPI, and I let the view controller call that method and have it set as the delegate of the store so it can be alerted when the data is returned. But wouldn’t it be better for the controller to not know about the api, but for it to just ask for the item and the store to either get it from the api or the local core data depending on what’s necessary?

Hope this makes sense. Thanks so much.