Publisher
extension Publisher
extension Publisher where Output: ThreadConfined
-
Freezes all Realm objects and collections emitted by the upstream publisher
Freezing a Realm object makes it no longer live-update when writes are made to the Realm and makes it safe to pass freely between threads without using
.threadSafeReference().// Get a publisher for a Results let cancellable = myResults.publisher // Convert to frozen Results .freeze() // Unlike live objects, frozen objects can be sent to a concurrent queue .receive(on: DispatchQueue.global()) .sink { frozenResults in // Do something with the frozen Results }Declaration
Swift
public func freeze<T>() -> Publishers.Map<Self, T> where T : ThreadConfined, T == Self.OutputReturn Value
A publisher that publishes frozen copies of the objects which the upstream publisher publishes.
-
Freezes all Realm object changesets emitted by the upstream publisher.
Freezing a Realm object changeset makes the included object reference no longer live-update when writes are made to the Realm and makes it safe to pass freely between threads without using
.threadSafeReference(). It also guarantees that the frozen object contained in the changeset will always match the property changes, which is not always the case when using thread-safe references.// Get a changeset publisher for an object let cancellable = changesetPublisher(object) // Convert to frozen changesets .freeze() // Unlike live objects, frozen objects can be sent to a concurrent queue .receive(on: DispatchQueue.global()) .sink { changeset in // Do something with the frozen changeset }Declaration
Swift
public func freeze<T>() -> Publishers.Map<Self, ObjectChange<T>> where T : RealmSwiftObject, Self.Output == ObjectChange<T>Return Value
A publisher that publishes frozen copies of the changesets which the upstream publisher publishes.
-
Freezes all Realm collection changesets from the upstream publisher.
Freezing a Realm collection changeset makes the included collection reference no longer live-update when writes are made to the Realm and makes it safe to pass freely between threads without using
.threadSafeReference(). It also guarantees that the frozen collection contained in the changeset will always match the change information, which is not always the case when using thread-safe references.// Get a changeset publisher for a collection let cancellable = myList.changesetPublisher // Convert to frozen changesets .freeze() // Unlike live objects, frozen objects can be sent to a concurrent queue .receive(on: DispatchQueue.global()) .sink { changeset in // Do something with the frozen changeset }Declaration
Swift
public func freeze<T: RealmCollection>() -> Publishers.Map<Self, RealmCollectionChange<T>> where Output == RealmCollectionChange<T>Return Value
A publisher that publishes frozen copies of the changesets which the upstream publisher publishes.
-
Freezes all Realm sectioned results changesets from the upstream publisher.
Freezing a Realm sectioned results changeset makes the included sectioned results reference no longer live-update when writes are made to the Realm and makes it safe to pass freely between threads without using
.threadSafeReference(). It also guarantees that the frozen sectioned results contained in the changeset will always match the change information, which is not always the case when using thread-safe references.// Get a changeset publisher for the sectioned results let cancellable = mySectionedResults.changesetPublisher // Convert to frozen changesets .freeze() // Unlike live objects, frozen objects can be sent to a concurrent queue .receive(on: DispatchQueue.global()) .sink { changeset in // Do something with the frozen changeset }Declaration
Swift
public func freeze<T: RealmSectionedResult>() -> Publishers.Map<Self, SectionedResultsChange<T>> where Output == SectionedResultsChange<T>Return Value
A publisher that publishes frozen copies of the changesets which the upstream publisher publishes.
-
Freezes all Realm collection changesets from the upstream publisher.
Freezing a Realm collection changeset makes the included collection reference no longer live-update when writes are made to the Realm and makes it safe to pass freely between threads without using
.threadSafeReference(). It also guarantees that the frozen collection contained in the changeset will always match the change information, which is not always the case when using thread-safe references.// Get a changeset publisher for a collection let cancellable = myMap.changesetPublisher // Convert to frozen changesets .freeze() // Unlike live objects, frozen objects can be sent to a concurrent queue .receive(on: DispatchQueue.global()) .sink { changeset in // Do something with the frozen changeset }Declaration
Swift
public func freeze<T: RealmKeyedCollection>() -> Publishers.Map<Self, RealmMapChange<T>> where Output == RealmMapChange<T>Return Value
A publisher that publishes frozen copies of the changesets which the upstream publisher publishes.
-
Freezes all Realm projection changesets emitted by the upstream publisher.
Freezing a Realm projection changeset makes the included projection reference no longer live-update when writes are made to the Realm and makes it safe to pass freely between threads without using
.threadSafeReference(). It also guarantees that the frozen projection contained in the changeset will always match the property changes, which is not always the case when using thread-safe references.// Get a changeset publisher for an projection let cancellable = changesetPublisher(projection) // Convert to frozen changesets .freeze() // Unlike live projections, frozen projections can be sent to a concurrent queue .receive(on: DispatchQueue.global()) .sink { changeset in // Do something with the frozen changeset }Declaration
Swift
public func freeze<T: ProjectionObservable>() -> Publishers.Map<Self, ObjectChange<T>> where Output == ObjectChange<T>, T: ThreadConfinedReturn Value
A publisher that publishes frozen copies of the changesets which the upstream publisher publishes.
-
Enables passing object changesets to a different dispatch queue.
Each call to
receive(on:)on a publisher which emits Realm thread-confined objects must be proceeded by a call to.threadSafeReference(). The returned publisher handles the required logic to pass the thread-confined object to the new queue. Only serial dispatch queues are supported and using other schedulers will result in a fatal error.For example, to subscribe on a background thread, do some work there, then pass the object changeset to the main thread you can do:
let cancellable = changesetPublisher(myObject) .subscribe(on: DispatchQueue(label: "background queue") .print() .threadSafeReference() .receive(on: DispatchQueue.main) .sink { objectChange in // Do things with the object on the main thread }Declaration
Swift
public func threadSafeReference<T: Object>() -> RealmPublishers.MakeThreadSafeObjectChangeset<Self, T> where Output == ObjectChange<T>Return Value
A publisher that supports
receive(on:)for thread-confined objects. -
Enables passing projection changesets to a different dispatch queue.
Each call to
receive(on:)on a publisher which emits Realm thread-confined projection must be proceeded by a call to.threadSafeReference(). The returned publisher handles the required logic to pass the thread-confined projection to the new queue. Only serial dispatch queues are supported and using other schedulers will result in a fatal error.For example, to subscribe on a background thread, do some work there, then pass the projection changeset to the main thread you can do:
let cancellable = changesetPublisher(myProjection) .subscribe(on: DispatchQueue(label: "background queue") .print() .threadSafeReference() .receive(on: DispatchQueue.main) .sink { projectionChange in // Do things with the projection on the main thread }Declaration
Swift
public func threadSafeReference<T: ProjectionObservable>() -> RealmPublishers.MakeThreadSafeObjectChangeset<Self, T> where Output == ObjectChange<T>, T: ThreadConfinedReturn Value
A publisher that supports
receive(on:)for thread-confined objects. -
Enables passing Realm collection changesets to a different dispatch queue.
Each call to
receive(on:)on a publisher which emits Realm thread-confined objects must be proceeded by a call to.threadSafeReference(). The returned publisher handles the required logic to pass the thread-confined object to the new queue. Only serial dispatch queues are supported and using other schedulers will result in a fatal error.For example, to subscribe on a background thread, do some work there, then pass the collection changeset to the main thread you can do:
let cancellable = myCollection.changesetPublisher .subscribe(on: DispatchQueue(label: "background queue") .print() .threadSafeReference() .receive(on: DispatchQueue.main) .sink { collectionChange in // Do things with the collection on the main thread }Declaration
Swift
public func threadSafeReference<T: RealmCollection>() -> RealmPublishers.MakeThreadSafeCollectionChangeset<Self, T> where Output == RealmCollectionChange<T>Return Value
A publisher that supports
receive(on:)for thread-confined objects. -
Enables passing Realm collection changesets to a different dispatch queue.
Each call to
receive(on:)on a publisher which emits Realm thread-confined objects must be proceeded by a call to.threadSafeReference(). The returned publisher handles the required logic to pass the thread-confined object to the new queue. Only serial dispatch queues are supported and using other schedulers will result in a fatal error.For example, to subscribe on a background thread, do some work there, then pass the collection changeset to the main thread you can do:
let cancellable = myCollection.changesetPublisher .subscribe(on: DispatchQueue(label: "background queue") .print() .threadSafeReference() .receive(on: DispatchQueue.main) .sink { collectionChange in // Do things with the collection on the main thread }Declaration
Swift
public func threadSafeReference<T: RealmKeyedCollection>() -> RealmPublishers.MakeThreadSafeKeyedCollectionChangeset<Self, T> where Output == RealmMapChange<T>Return Value
A publisher that supports
receive(on:)for thread-confined objects. -
Enables passing Realm sectioned results changesets to a different dispatch queue.
Each call to
receive(on:)on a publisher which emits Realm thread-confined objects must be proceeded by a call to.threadSafeReference(). The returned publisher handles the required logic to pass the thread-confined object to the new queue. Only serial dispatch queues are supported and using other schedulers will result in a fatal error.For example, to subscribe on a background thread, do some work there, then pass the collection changeset to the main thread you can do:
let cancellable = mySectionedResults.changesetPublisher .subscribe(on: DispatchQueue(label: "background queue") .print() .threadSafeReference() .receive(on: DispatchQueue.main) .sink { sectionedResultsChange in // Do things with the sectioned results on the main thread }Declaration
Swift
public func threadSafeReference<T: RealmSectionedResult>() -> RealmPublishers.MakeThreadSafeSectionedResultsChangeset<Self, T> where Output == SectionedResultsChange<T>Return Value
A publisher that supports
receive(on:)for thread-confined objects.
-
Enables passing thread-confined objects to a different dispatch queue.
Each call to
receive(on:)on a publisher which emits Realm thread-confined objects must be proceeded by a call to.threadSafeReference().The returned publisher handles the required logic to pass the thread-confined object to the new queue. Only serial dispatch queues are supported and using other schedulers will result in a fatal error.For example, to subscribe on a background thread, do some work there, then pass the object to the main thread you can do:
let cancellable = publisher(myObject) .subscribe(on: DispatchQueue(label: "background queue") .print() .threadSafeReference() .receive(on: DispatchQueue.main) .sink { object in // Do things with the object on the main thread }Calling this function on a publisher which emits frozen or unmanaged objects is unneccesary but is allowed.
Declaration
Swift
public func threadSafeReference() -> RealmPublishers.MakeThreadSafe<Self>Return Value
A publisher that supports
receive(on:)for thread-confined objects.
View on GitHub
Install in Dash