# ObjectObserver

    public protocol ObjectObserver : AnyObject

Implement the `ObjectObserver` protocol to observe changes to a single `DynamicObject` instance. `ObjectObserver`s may register themselves to an `ObjectMonitor`‘s `addObserver(_:)` method:

    let monitor = dataStack.monitorObject(object)
    monitor.addObserver(self)

- `ObjectEntityType`

  The `DynamicObject` type for the observed object

  #### Declaration

  Swift

      associatedtype ObjectEntityType : DynamicObject

- `objectMonitor(_:willUpdateObject:sourceIdentifier:)` Default implementation

  Handles processing just before a change to the observed `object` occurs. (Optional) The default implementation does nothing.

  #### Default Implementation

  #### Declaration

  Swift

      func objectMonitor(
          _ monitor: ObjectMonitor<ObjectEntityType>,
          willUpdateObject object: ObjectEntityType,
          sourceIdentifier: Any?
      )

  #### Parameters

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

- `objectMonitor(_:willUpdateObject:)` Default implementation

  Handles processing just before a change to the observed `object` occurs. (Optional) The default implementation does nothing.

  #### Default Implementation

  #### Declaration

  Swift

      func objectMonitor(
          _ monitor: ObjectMonitor<ObjectEntityType>,
          willUpdateObject object: ObjectEntityType
      )

  #### Parameters

  `monitor` | the `ObjectMonitor` monitoring the object being observed
  `object` | the `DynamicObject` instance being observed

- `objectMonitor(_:didUpdateObject:changedPersistentKeys:sourceIdentifier:)` Default implementation

  Handles processing right after a change to the observed `object` occurs. (Optional) The default implementation does nothing.

  #### Default Implementation

  #### Declaration

  Swift

      func objectMonitor(
          _ monitor: ObjectMonitor<ObjectEntityType>,
          didUpdateObject object: ObjectEntityType,
          changedPersistentKeys: Set<KeyPathString>,
          sourceIdentifier: Any?
      )

  #### Parameters

  `monitor` | the `ObjectMonitor` monitoring the object being observed
  `object` | the `DynamicObject` instance being observed
  `changedPersistentKeys` | a `Set` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported.
  `sourceIdentifier` | an optional identifier provided by the transaction source

- `objectMonitor(_:didUpdateObject:changedPersistentKeys:)` Default implementation

  Handles processing right after a change to the observed `object` occurs. (Optional) The default implementation does nothing.

  #### Default Implementation

  #### Declaration

  Swift

      func objectMonitor(
          _ monitor: ObjectMonitor<ObjectEntityType>,
          didUpdateObject object: ObjectEntityType,
          changedPersistentKeys: Set<KeyPathString>
      )

  #### Parameters

  `monitor` | the `ObjectMonitor` monitoring the object being observed
  `object` | the `DynamicObject` instance being observed
  `changedPersistentKeys` | a `Set` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported.

- `objectMonitor(_:didDeleteObject:sourceIdentifier:)` Default implementation

  Handles processing right after `object` is deleted. (Optional) The default implementation does nothing.

  #### Default Implementation

  #### Declaration

  Swift

      func objectMonitor(
          _ monitor: ObjectMonitor<ObjectEntityType>,
          didDeleteObject object: ObjectEntityType,
          sourceIdentifier: Any?
      )

  #### Parameters

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

- `objectMonitor(_:didDeleteObject:)` Default implementation

  Handles processing right after `object` is deleted. (Optional) The default implementation does nothing.

  #### Default Implementation

  #### Declaration

  Swift

      func objectMonitor(
          _ monitor: ObjectMonitor<ObjectEntityType>,
          didDeleteObject object: ObjectEntityType
      )

  #### Parameters

  `monitor` | the `ObjectMonitor` monitoring the object being observed
  `object` | the `DynamicObject` instance being observed