From 6a006d5d7c93d96199493524640beec4e8c6c132 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Tue, 8 Sep 2015 18:12:52 +0900 Subject: [PATCH] added a flag to inspect the current state of a refetch --- CoreStore/Observing/ListMonitor.swift | 16 +++++++++++++++- .../ListObserverDemoViewController.swift | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 3bfdaff..b22c8df 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -69,7 +69,7 @@ In the example above, both `person1` and `person2` will contain the object at se */ public final class ListMonitor { - // MARK: Public + // MARK: Public (Accessors) /** Returns the object at the given index within the first section. This subscript indexer is typically used for `ListMonitor`s created with `monitorList(_:)`. @@ -308,6 +308,9 @@ public final class ListMonitor { return self.fetchedResultsController.indexPathForObject(object) } + + // MARK: Public (Observers) + /** Registers a `ListObserver` to be notified when changes to the receiver's list occur. @@ -734,6 +737,14 @@ public final class ListMonitor { setAssociatedRetainedObject(nilValue, forKey: &self.didDeleteSectionKey, inObject: observer) } + + // MARK: Public (Refetching) + + /** + Returns `true` if a call to `refetch(...)` was made to the `ListMonitor` and is currently waiting for the fetching to complete. Returns `false` otherwise. + */ + private(set) public var isPendingRefetch = false + /** Asks the `ListMonitor` to refetch its objects using the specified series of `FetchClause`s. Note that this method does not execute the fetch immediately; the actual fetching will happen after the `NSFetchedResultsController`'s last `controllerDidChangeContent(_:)` notification completes. @@ -755,6 +766,8 @@ public final class ListMonitor { */ public func refetch(fetchClauses: [FetchClause]) { + self.isPendingRefetch = true + NSNotificationCenter.defaultCenter().postNotificationName( ListMonitorWillRefetchListNotification, object: self @@ -774,6 +787,7 @@ public final class ListMonitor { } try! strongSelf.fetchedResultsController.performFetch() + strongSelf.isPendingRefetch = false NSNotificationCenter.defaultCenter().postNotificationName( ListMonitorDidRefetchListNotification, diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift index 49d2473..8423089 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ListObserverDemoViewController.swift @@ -109,6 +109,8 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver self.filterBarButton = filterBarButton Static.palettes.addObserver(self) + + self.setTableEnabled(!Static.palettes.isPendingRefetch) } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {