SyncSubscriptionSet

@frozen
public struct SyncSubscriptionSet
extension SyncSubscriptionSet: Sequence

SyncSubscriptionSet is a collection of SyncSubscriptions. This is the entry point for adding and removing SyncSubscriptions.

Initializers

  • The number of subscriptions in the subscription set.

    Declaration

    Swift

    public var count: Int { get }
  • Synchronously performs any transactions (add/remove/update) to the subscription set within the block.

    Declaration

    Swift

    public func update(_ block: (() -> Void), onComplete: (@Sendable (Error?) -> Void)? = nil)

    Parameters

    block

    The block containing the subscriptions transactions to perform.

    onComplete

    The block called upon synchronization of subscriptions to the server. Otherwise an Errordescribing what went wrong will be returned by the block

  • Returns the current state for the subscription set.

    Declaration

    Swift

    public var state: SyncSubscriptionState { get }
  • Returns a subscription by the specified name.

    Declaration

    Swift

    public func first(named: String) -> SyncSubscription?

    Parameters

    named

    The name of the subscription searching for.

    Return Value

    A subscription for the given name.

  • Returns a subscription by the specified query.

    Declaration

    Swift

    public func first<T>(ofType type: T.Type, where query: (Query<T>) -> Query<Bool>) -> SyncSubscription? where T : RealmSwiftObject

    Parameters

    type

    The type of the object to be queried.

    where

    A query builder that produces a subscription which can be used to search the subscription by query and/or name.

    Return Value

    A query builder that produces a subscription which can used to search for the subscription.

  • Returns a subscription by the specified query.

    Declaration

    Swift

    public func first<T>(ofType type: T.Type, where predicateFormat: String, _ args: Any...) -> SyncSubscription? where T : RealmSwiftObject

    Parameters

    type

    The type of the object to be queried.

    where

    A query builder that produces a subscription which can be used to search the subscription by query and/or name.

    Return Value

    A query builder that produces a subscription which can used to search for the subscription.

  • Returns a subscription by the specified query.

    Declaration

    Swift

    public func first<T>(ofType type: T.Type, where predicate: NSPredicate) -> SyncSubscription? where T : RealmSwiftObject

    Parameters

    type

    The type of the object to be queried.

    where

    A query builder that produces a subscription which can be used to search the subscription by query and/or name.

    Return Value

    A query builder that produces a subscription which can used to search for the subscription.

  • Appends one or several subscriptions to the subscription set.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func append<T>(_ subscriptions: QuerySubscription<T>...) where T : RealmSwiftObject

    Parameters

    subscriptions

    The subscriptions to be added to the subscription set.

  • Removes a subscription with the specified query.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func remove<T>(ofType type: T.Type, _ query: @escaping (Query<T>) -> Query<Bool>) where T : RealmSwiftObject

    Parameters

    type

    The type of the object to be removed.

    to

    A query for the subscription to be removed from the subscription set.

  • Removes a subscription with the specified query.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func remove<T>(ofType type: T.Type, where predicateFormat: String, _ args: Any...) where T : RealmSwiftObject

    Parameters

    type

    The type of the object to be removed.

    predicateFormat

    A predicate format string, optionally followed by a variable number of arguments, which will be used to identify the subscription to be removed.

  • Removes a subscription with the specified query.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func remove<T>(ofType type: T.Type, where predicate: NSPredicate) where T : RealmSwiftObject

    Parameters

    type

    The type of the object to be removed.

    predicate

    The predicate which will be used to identify the subscription to be removed.

  • Removes one or several subscriptions from the subscription set.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func remove(_ subscriptions: SyncSubscription...)

    Parameters

    subscription

    The subscription to be removed from the subscription set.

  • Removes a subscription with the specified name from the subscription set.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func remove(named: String)

    Parameters

    named

    The name of the subscription to be removed from the subscription set.

  • Removes all subscriptions from the subscription set.

    Warning

    This method may only be called during a write subscription block.

    Warning

    Removing all subscriptions will result in an error if no new subscription is added. Server should acknowledge at least one subscription.

    Declaration

    Swift

    public func removeAll(unnamedOnly: Bool = false)

    Parameters

    unnamedOnly

    If true, only unnamed subscriptions are removed.

  • Removes zero or none subscriptions of the given type from the subscription set.

    Warning

    This method may only be called during a write subscription block.

    Declaration

    Swift

    public func removeAll<T>(ofType type: T.Type) where T : RealmSwiftObject

    Parameters

    type

    The type of the objects to be removed.

Subscription Retrieval

  • Returns the subscription at the given position.

    Declaration

    Swift

    public subscript(position: Int) -> SyncSubscription? { get }

    Parameters

    position

    The index for the resulting subscription.

  • Returns the first object in the SyncSubscription list, or nil if the subscriptions are empty.

    Declaration

    Swift

    public var first: SyncSubscription? { get }
  • Returns the last object in the SyncSubscription list, or nil if the subscriptions are empty.

    Declaration

    Swift

    public var last: SyncSubscription? { get }

Sequence Support

  • Returns a SyncSubscriptionSetIterator that yields successive elements in the subscription collection.

    Declaration

    Swift

    public func makeIterator() -> SyncSubscriptionSetIterator
  • update(_:) Asynchronous

    Creates and commits a transaction, updating the subscription set, this will continue when the server acknowledge and all the data associated with this collection of subscriptions is synced.

    Throws

    An NSError if the subscription set state changes to an error state or there is and error while committing any changes to the subscriptions.

    Declaration

    Swift

    @MainActor
    public func update(_ block: (() -> Void)) async throws

    Parameters

    block

    The block containing the subscriptions transactions to perform.

  • Creates and commit a transaction, updating the subscription set, this will return success when the server acknowledge and all the data associated with this collection of subscriptions is synced.

    Declaration

    Swift

    public func updateSubscriptions(_ block: @escaping (() -> Void)) -> Future<Void, Error>

    Parameters

    block

    The block containing the subscriptions transactions to perform.

    Return Value

    A publisher that eventually returns Result.success or Error.