MotionInMotion Episode 16 - NSFetchedResultsController
NSFetchedResultsController - MotionInMotion
単純なTaskモデルのCRUD
- NSFetchedResultsControllerを使ってCoreDataに保存
- easy to maintain
- table views will be faster
- memory usage will go down
- TaskListController
- viewDidLoad
- private def fetch_controller
- @fetch_controller ||= NSFetchedResultsController.alloc.initWithFetchRequest(
- @tasks.fetch_request
- @fetch_controller ||= NSFetchedResultsController.alloc.initWithFetchRequest(
- Notification Handlers
- context_did_save
- Dispatch::Queue.main.async do
- fetch_controller.managedObjectContext.mergeChangesFromContextDidSaveNotification(notification)
- Dispatch::Queue.main.async do
- context_did_save
- NSFetchedResultsControllerDelegate
- controllerWillChangeContent(controller)
- view.beginUpdates
- controller didChangeObject atIndexPath forChangeType newIndexPath
- case change_type
- NSFetchedResultsChangeInsert / NSFetchedResultsChangeDelete / NSFetchedResultsChangeUpdate
- view.insert/delete/relaodRowsAtIndexPaths withRowAnimation: UITableViewRowAnimationAutomatic
- case change_type
- controllerWillChangeContent(controller)
- UITableViewDelegate
- editingStyleForRowAtIndexPath
- canEditRowAtIndexPath
- commitEditingStyle commitEditingStyle
- didSelectRowAtIndexPath