# ListObserver

    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 = dataStack.monitorList(
        From<Person>(),
        OrderBy(.ascending("lastName"))
    )
    monitor.addObserver(self)

- `ListEntityType`

  The `NSManagedObject` type for the observed list

  #### Declaration

  Swift

      associatedtype ListEntityType : DynamicObject

- `listMonitorWillChange(_:sourceIdentifier:)` Default implementation

  Handles 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>,
          sourceIdentifier: Any?
      )

  #### Parameters

  `monitor` | the `ListMonitor` monitoring the list being observed
  `sourceIdentifier` | an optional identifier provided by the transaction source

- `listMonitorWillChange(_:)` Default implementation

  Handles 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

- `listMonitorDidChange(_:sourceIdentifier:)` Default implementation

  Handles processing right after a change to the observed list occurs. (Required)

  #### Default Implementation

  #### Declaration

  Swift

      func listMonitorDidChange(
          _ monitor: ListMonitor<ListEntityType>,
          sourceIdentifier: Any?
      )

  #### Parameters

  `monitor` | the `ListMonitor` monitoring the object being observed
  `sourceIdentifier` | an optional identifier provided by the transaction source

- `listMonitorDidChange(_:)`

  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(_:sourceIdentifier:)` Default implementation

  This method is broadcast from within the `ListMonitor`‘s `refetch(...)` method to let observers prepare for the internal `NSFetchedResultsController`’s pending change to its predicate, sort descriptors, etc. (Optional)

  Important

  All `ListMonitor` access between `listMonitorWillRefetch(_:)` and `listMonitorDidRefetch(_:)` will raise and assertion. The actual refetch will happen after the `NSFetchedResultsController`’s last `controllerDidChangeContent(_:)` notification completes.

  #### Default Implementation

  #### Declaration

  Swift

      func listMonitorWillRefetch(
          _ monitor: ListMonitor<ListEntityType>,
          sourceIdentifier: Any?
      )

  #### Parameters

  `monitor` | the `ListMonitor` monitoring the object being observed
  `sourceIdentifier` | an optional identifier provided by the transaction source

- `listMonitorWillRefetch(_:)` Default implementation

  This method is broadcast from within the `ListMonitor`‘s `refetch(...)` method to let observers prepare for the internal `NSFetchedResultsController`’s pending change to its predicate, sort descriptors, etc. (Optional)

  Important

  All `ListMonitor` access between `listMonitorWillRefetch(_:)` and `listMonitorDidRefetch(_:)` will raise and assertion. The actual refetch will happen after the `NSFetchedResultsController`’s last `controllerDidChangeContent(_:)` notification completes.

  #### Default Implementation

  #### Declaration

  Swift

      func listMonitorWillRefetch(
          _ monitor: ListMonitor<ListEntityType>
      )

  #### Parameters

  `monitor` | the `ListMonitor` monitoring the object being observed

- `listMonitorDidRefetch(_:sourceIdentifier:)` Default implementation

  After the `ListMonitor`‘s `refetch(...)` method is called, this method is broadcast after the `NSFetchedResultsController`’s last `controllerDidChangeContent(_:)` notification completes. (Required)

  Important

  When `listMonitorDidRefetch(_:)` is called it should be assumed that all `ListMonitor`’s previous data have been reset, including counts, objects, and persistent stores.

  #### Default Implementation

  #### Declaration

  Swift

      func listMonitorDidRefetch(
          _ monitor: ListMonitor<ListEntityType>,
          sourceIdentifier: Any?
      )

  #### Parameters

  `monitor` | the `ListMonitor` monitoring the object being observed
  `sourceIdentifier` | an optional identifier provided by the transaction source

- `listMonitorDidRefetch(_:)`

  After the `ListMonitor`‘s `refetch(...)` method is called, this method is broadcast after the `NSFetchedResultsController`’s last `controllerDidChangeContent(_:)` notification completes. (Required)

  Important

  When `listMonitorDidRefetch(_:)` is called it should be assumed that all `ListMonitor`’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