added a flag to inspect the current state of a refetch

This commit is contained in:
John Estropia
2015-09-08 18:12:52 +09:00
parent 399517e357
commit 6a006d5d7c
2 changed files with 17 additions and 1 deletions

View File

@@ -69,7 +69,7 @@ In the example above, both `person1` and `person2` will contain the object at se
*/
public final class ListMonitor<T: NSManagedObject> {
// 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<T: NSManagedObject> {
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<T: NSManagedObject> {
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<T: NSManagedObject> {
*/
public func refetch(fetchClauses: [FetchClause]) {
self.isPendingRefetch = true
NSNotificationCenter.defaultCenter().postNotificationName(
ListMonitorWillRefetchListNotification,
object: self
@@ -774,6 +787,7 @@ public final class ListMonitor<T: NSManagedObject> {
}
try! strongSelf.fetchedResultsController.performFetch()
strongSelf.isPendingRefetch = false
NSNotificationCenter.defaultCenter().postNotificationName(
ListMonitorDidRefetchListNotification,

View File

@@ -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?) {