mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-31 14:43:09 +02:00
added a flag to inspect the current state of a refetch
This commit is contained in:
@@ -69,7 +69,7 @@ In the example above, both `person1` and `person2` will contain the object at se
|
|||||||
*/
|
*/
|
||||||
public final class ListMonitor<T: NSManagedObject> {
|
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(_:)`.
|
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)
|
return self.fetchedResultsController.indexPathForObject(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: Public (Observers)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Registers a `ListObserver` to be notified when changes to the receiver's list occur.
|
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)
|
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.
|
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]) {
|
public func refetch(fetchClauses: [FetchClause]) {
|
||||||
|
|
||||||
|
self.isPendingRefetch = true
|
||||||
|
|
||||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||||
ListMonitorWillRefetchListNotification,
|
ListMonitorWillRefetchListNotification,
|
||||||
object: self
|
object: self
|
||||||
@@ -774,6 +787,7 @@ public final class ListMonitor<T: NSManagedObject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try! strongSelf.fetchedResultsController.performFetch()
|
try! strongSelf.fetchedResultsController.performFetch()
|
||||||
|
strongSelf.isPendingRefetch = false
|
||||||
|
|
||||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||||
ListMonitorDidRefetchListNotification,
|
ListMonitorDidRefetchListNotification,
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ class ListObserverDemoViewController: UITableViewController, ListSectionObserver
|
|||||||
self.filterBarButton = filterBarButton
|
self.filterBarButton = filterBarButton
|
||||||
|
|
||||||
Static.palettes.addObserver(self)
|
Static.palettes.addObserver(self)
|
||||||
|
|
||||||
|
self.setTableEnabled(!Static.palettes.isPendingRefetch)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user