A simple but complete Core Data app that displays repos of GitHub users
The aim here is a simple but relatively real and complete sample Core Data app. To be relatively complete, it needs to touch upon how Core Data
- Interacts with networking,
- Could be used as structured cache for a REST API,
- Deals concurrency,
- Works with NSFetchedResultsController in a UITableView (or UICollectionView) context, and
- Handles multiple entities with relationships among them.
A combination of these probably covers most requirements from most simple apps. (What is not demonstrated here is how Core Data supports manipulation of complext object graph, which is presumably the real deal about Core Data.) To make this sample app real enough, the GitHub API is used to pull some basic information about repos of GitHub users that one can interactively input into the app. To keep the app simple, other than iOS SDK, no other library was used.
There is a lot of good resources out there. The followiing -- mostly about concurrency -- specifically inspired this project:
-
A Complete Core Data Application; GitHub repo here
One of the best Core Data tutorials. Quite elegant.
-
Core Data with multiple managed object contexts; GitHub repo here
-
NSManagedObjectContext’s parentContext
Parent context clearly explained.
-
Not the easiest to read. But worth going back again and again.
-
WWWDC 2014 What's New in Core Data
Fair amount of helpful information.
The followng posts were also helpful:
- http://robots.thoughtbot.com/core-data
- http://www.cocoanetics.com/2012/07/multi-context-coredata/
- http://www.cimgf.com/2011/05/04/core-data-and-threads-without-the-headache/
While the project follows the three-tier stack (attributed to Marcus Zarra) in dealing with context and concurrency, we should keep in mind these compelling findings:
The project was done with Xcode 6 and targets iOS 8. While the debugging flag com.apple.CoreData.ConcurrencyDebug -- see WWWDC 2014 What's New in Core Data -- did seem to be useful, the bug reported here:
seems real and seems to remain there in iOS 8 beta 3.
The new iOS 8 NSAsynchronousFetchRequst was also tried, but it simply couldn't be made to work in the current iOS 8 beta. It would be something good to include in a future update to this project.
- The app does not play well with GitHub API's rate limiting.
- Much to be refactored (always the case) Specifically, UserViewController & RepoViewController could be made better.