NorimasaNabeta / CoreDataSPoT

Stanford CS193p 2013 Winter HomeWork5
0 stars 0 forks source link

RT6 Refetch #6

Open NorimasaNabeta opened 11 years ago

NorimasaNabeta commented 11 years ago

When the user refreshes the table view (with the UIRefreshControl), you should refetch the data from Flickr in a thread and update your Core Data database and then update the UI to show any new data. This refresh should automatically invoke upon launch of your application if the Core Data database is empty.

NorimasaNabeta commented 11 years ago

HINT15 It is probably a good idea to invoke all Core Data operations in the main thread for this assignment. It may be more “correct” to do some of those operations in other threads, but that requires a much better understanding of how Core Data uses threads than we are able to cover in this course (though you are more than welcome to try to figure this out). NSManagedObjectContext’s performBlock: would be the best way to get Core Data operations onto the right thread.

NorimasaNabeta commented 11 years ago

HINT14 Note that your user-interface will automatically update when you make modifications to the database that it is hooked up to. That is the wonder of NSFetchedResultsController and Core Data’s use of the key-value observing mechanism.

NorimasaNabeta commented 11 years ago

HINT11 NSFetchedResultsController has a property called fetchedObjects which is the array of NSManagedObjects it fetched. Checking whether this array is empty (empty, not nil) is probably a good way to figure out whether to “auto-fetch” when your application runs and there is no data in the database. If fetchedObjects is nil, it means the fetch has not been attempted yet. Pick a spot in your View Controller’s Lifecycle where the fetch has happened before you check to see if the fetch came back with no results. When you implement methods in your View Controller’s Lifecycle, be sure not to forget to invoke your super’s implementation so that CoreDataTableViewController can do what it wants to do too.