ListObserver
@available(OSX 10.12, *)
public protocol ListObserver : AnyObject
Implement the ListObserver
protocol to observe changes to a list of NSManagedObject
s. ListObserver
s may register themselves to a ListMonitor
‘s addObserver(_:)
method:
let monitor = CoreStore.monitorList(
From<Person>(),
OrderBy(.ascending("lastName"))
)
monitor.addObserver(self)
-
The
NSManagedObject
type for the observed listDeclaration
Swift
associatedtype ListEntityType : DynamicObject
-
listMonitorWillChange(_:)
Default implementationHandles processing just before a change to the observed list occurs. (Optional) The default implementation does nothing.
Default Implementation
Declaration
Swift
func listMonitorWillChange(_ monitor: ListMonitor<ListEntityType>)
Parameters
monitor
the
ListMonitor
monitoring the list being observed -
Handles processing right after a change to the observed list occurs. (Required)
Declaration
Swift
func listMonitorDidChange(_ monitor: ListMonitor<ListEntityType>)
Parameters
monitor
the
ListMonitor
monitoring the object being observed -
listMonitorWillRefetch(_:)
Default implementationThis method is broadcast from within the
ListMonitor
‘srefetch(...)
method to let observers prepare for the internalNSFetchedResultsController
’s pending change to its predicate, sort descriptors, etc. (Optional)Important
AllListMonitor
access betweenlistMonitorWillRefetch(_:)
andlistMonitorDidRefetch(_:)
will raise and assertion. The actual refetch will happen after theNSFetchedResultsController
’s lastcontrollerDidChangeContent(_:)
notification completes.Default Implementation
Declaration
Swift
func listMonitorWillRefetch(_ monitor: ListMonitor<ListEntityType>)
Parameters
monitor
the
ListMonitor
monitoring the object being observed -
After the
ListMonitor
‘srefetch(...)
method is called, this method is broadcast after theNSFetchedResultsController
’s lastcontrollerDidChangeContent(_:)
notification completes. (Required)Important
WhenlistMonitorDidRefetch(_:)
is called it should be assumed that allListMonitor
’s previous data have been reset, including counts, objects, and persistent stores.Declaration
Swift
func listMonitorDidRefetch(_ monitor: ListMonitor<ListEntityType>)
Parameters
monitor
the
ListMonitor
monitoring the object being observed