ProjectionChangeset

@frozen
public struct ProjectionChangeset<P> : Publisher where P : ProjectionObservable, P : ThreadConfined

A publisher which emits ObjectChange each time the observed projection is modified

receive(on:) and subscribe(on:) can be called directly on this publisher, and calling .threadSafeReference() is only required if there is an intermediate transform. If subscribe(on:) is used, it should always be the first operation in the pipeline.

Create this publisher using the changesetPublisher() function.

  • This publisher emits a ProjectionChange

    indicating which projection and which properties of that projection have changed each time a Realm is refreshed after a write transaction which modifies the observed projection.

    Declaration

    Swift

    public typealias Output = ObjectChange<P>
  • This publisher reports error via the .error case of ProjectionChange.

    Declaration

    Swift

    public typealias Failure = Never
  • Captures the NotificationToken produced by observing a Realm Collection.

    This allows you to do notification skipping when performing a Realm.write(withoutNotifying:). You should use this call if you require to write to the Realm database and ignore this specific observation chain. The NotificationToken will be saved on the specified KeyPathfrom the observation block set up in receive(subscriber:).

    Declaration

    Swift

    public func saveToken<T>(on tokenParent: T, at keyPath: WritableKeyPath<T, NotificationToken?>) -> ProjectionChangesetWithToken<T, P>

    Parameters

    projection

    The projection which the NotificationToken is written to.

    keyPath

    The KeyPath which the NotificationToken is written to.

    Return Value

    A ProjectionChangesetWithToken Publisher.

  • Specifies the scheduler on which to perform subscribe, cancel, and request operations.

    For Realm Publishers, this determines which queue the underlying change notifications are sent to. If receive(on:) is not used subsequently, it also will determine which queue elements received from the publisher are evaluated on. Currently only serial dispatch queues are supported, and the options: parameter is not supported.

    Declaration

    Swift

    public func subscribe<S>(on scheduler: S) -> ProjectionChangeset<P> where S : Scheduler

    Parameters

    scheduler

    The serial dispatch queue to perform the subscription on.

    Return Value

    A publisher which subscribes on the given scheduler.

  • Specifies the scheduler on which to perform downstream operations.

    This differs from subscribe(on:) in how it is integrated with the autorefresh cycle. When using subscribe(on:), the subscription is performed on the target scheduler and the publisher will emit the collection during the refresh. When using receive(on:), the collection is then converted to a ThreadSafeReference and delivered to the target scheduler with no integration into the autorefresh cycle, meaning it may arrive some time after the refresh occurs.

    When in doubt, you probably want subscribe(on:)

    Declaration

    Swift

    public func receive<S>(on scheduler: S) -> DeferredHandoverProjectionChangeset<`Self`, P, S> where S : Scheduler

    Parameters

    scheduler

    The serial dispatch queue to receive values on.

    Return Value

    A publisher which delivers values to the given scheduler.