From 283104af3f31bc7012b18799a0e43cf49ae066a0 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 9 Aug 2015 05:04:47 +0900 Subject: [PATCH] thanks to protocol extensions, you can now omit ListObserver and ObjectObserver methods you don't need to implement --- CoreStore/Observing/ListObserver.swift | 49 +++++++++++++++++++ CoreStore/Observing/ObjectObserver.swift | 19 +++++++ .../ObjectObserverDemoViewController.swift | 5 -- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/CoreStore/Observing/ListObserver.swift b/CoreStore/Observing/ListObserver.swift index 7a9581a..ccb18a7 100644 --- a/CoreStore/Observing/ListObserver.swift +++ b/CoreStore/Observing/ListObserver.swift @@ -60,6 +60,19 @@ public protocol ListObserver: class { func listMonitorDidChange(monitor: ListMonitor) } +public extension ListObserver { + + /** + The default implementation does nothing. + */ + func listMonitorWillChange(monitor: ListMonitor) { } + + /** + The default implementation does nothing. + */ + func listMonitorDidChange(monitor: ListMonitor) { } +} + // MARK: - ListObjectObserver @@ -112,6 +125,29 @@ public protocol ListObjectObserver: ListObserver { func listMonitor(monitor: ListMonitor, didMoveObject object: EntityType, fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) } +public extension ListObjectObserver { + + /** + The default implementation does nothing. + */ + func listMonitor(monitor: ListMonitor, didInsertObject object: EntityType, toIndexPath indexPath: NSIndexPath) { } + + /** + The default implementation does nothing. + */ + func listMonitor(monitor: ListMonitor, didDeleteObject object: EntityType, fromIndexPath indexPath: NSIndexPath) { } + + /** + The default implementation does nothing. + */ + func listMonitor(monitor: ListMonitor, didUpdateObject object: EntityType, atIndexPath indexPath: NSIndexPath) { } + + /** + The default implementation does nothing. + */ + func listMonitor(monitor: ListMonitor, didMoveObject object: EntityType, fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { } +} + // MARK: - ListSectionObserver @@ -145,3 +181,16 @@ public protocol ListSectionObserver: ListObjectObserver { */ func listMonitor(monitor: ListMonitor, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) } + +public extension ListSectionObserver { + + /** + The default implementation does nothing. + */ + func listMonitor(monitor: ListMonitor, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int) { } + + /** + The default implementation does nothing. + */ + func listMonitor(monitor: ListMonitor, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) { } +} diff --git a/CoreStore/Observing/ObjectObserver.swift b/CoreStore/Observing/ObjectObserver.swift index 40bcbc6..65118ff 100644 --- a/CoreStore/Observing/ObjectObserver.swift +++ b/CoreStore/Observing/ObjectObserver.swift @@ -67,3 +67,22 @@ public protocol ObjectObserver: class { */ func objectMonitor(monitor: ObjectMonitor, didDeleteObject object: EntityType) } + + +public extension ObjectObserver { + + /** + The default implementation does nothing. + */ + func objectMonitor(monitor: ObjectMonitor, willUpdateObject object: EntityType) { } + + /** + The default implementation does nothing. + */ + func objectMonitor(monitor: ObjectMonitor, didUpdateObject object: EntityType, changedPersistentKeys: Set) { } + + /** + The default implementation does nothing. + */ + func objectMonitor(monitor: ObjectMonitor, didDeleteObject object: EntityType) { } +} diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift index 2942f00..1a004aa 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift @@ -80,11 +80,6 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver { // MARK: ObjectObserver - func objectMonitor(monitor: ObjectMonitor, willUpdateObject object: Palette) { - - // none - } - func objectMonitor(monitor: ObjectMonitor, didUpdateObject object: Palette, changedPersistentKeys: Set) { self.reloadPaletteInfo(object, changedKeys: changedPersistentKeys)