public class SyncSubscription<Type: RealmCollectionValue>

SyncSubscription represents a subscription to a set of objects in a synced Realm.

When partial sync is enabled for a synced Realm, the only objects that the server synchronizes to the client are those that match a sync subscription registered by that client. A subscription consists of of a query (represented by a Results) and an optional name.

Changes to the state of the subscription can be observed using SyncSubscription.observe(_:options:_:).

Subscriptions are created using Results.subscribe() or Results.subscribe(named:).

  • Declaration


    public class SyncSubscription<Type: RealmCollectionValue>
  • The name of the subscription.

    This will be nil if a name was not provided when the subscription was created.



    public var name: String?
  • The state of the subscription.



    public var state: SyncSubscriptionState
  • Observe the subscription for state changes.

    When the state of the subscription changes, block will be invoked and passed the new state.

    The token returned from this function does not hold a strong reference to this subscription object. This means that you must hold a reference to the subscription object itself along with the returned token in order to actually receive updates about the state.



    public func observe(_ keyPath: KeyPath<SyncSubscription, SyncSubscriptionState>,
                            options: NSKeyValueObservingOptions = [],
                            _ block: @escaping (SyncSubscriptionState) -> Void) -> NotificationToken



    The path to observe. Must be \.state.


    Options for the observation. Only NSKeyValueObservingOptions.initial option is is supported at this time.


    The block to be called whenever a change occurs.

    Return Value

    A token which must be held for as long as you want updates to be delivered.

  • Remove this subscription

    Removing a subscription will delete all objects from the local Realm that were matched only by that subscription and not any remaining subscriptions. The deletion is performed by the server, and so has no immediate impact on the contents of the local Realm. If the device is currently offline, the removal will not be processed until the device returns online.



    public func unsubscribe()