RLMSyncSubscription
@interface RLMSyncSubscription : NSObject
RLMSyncSubscription
represents a subscription to a set of objects in a synced Realm.
When query-based sync is enabled for a synchronized Realm, the server only
synchronizes objects to the client when they match a sync subscription
registered by that client. A subscription consists of of a query (represented
by an RLMResults
) and an optional name.
The state of the subscription can be observed using
Key-Value Observing
on the state
property.
Subscriptions are created using -[RLMResults subscribe]
or
-[RLMResults subscribeWithName:]
. Existing subscriptions for a Realm can be
looked up with -[RLMRealm subscriptions]
or -[RLMRealm subscriptionWithName:]
.
-
The unique name for this subscription.
This will be
nil
if this object was created with-[RLMResults subscribe]
. Subscription objects read from a Realm with-[RLMRealm subscriptions]
will always have a non-nil
name and subscriptions which were not explicitly named will have an automatically generated one.Declaration
Objective-C
@property (readonly, nonatomic, nullable) NSString *name;
Swift
var name: String? { get }
-
The current state of the subscription. See
RLMSyncSubscriptionState
.Declaration
Objective-C
@property (readonly, nonatomic) RLMSyncSubscriptionState state;
Swift
var state: RLMSyncSubscriptionState { get }
-
The error which occurred when registering this subscription, if any.
Will be non-nil only when
state
isRLMSyncSubscriptionStateError
.Declaration
Objective-C
@property (readonly, nonatomic, nullable) NSError *error;
Swift
var error: Error? { get }
-
The raw query which this subscription is running on the server.
This string is a serialized representation of the RLMResults which the subscription was created from. This representation does not use NSPredicate syntax, and is not guaranteed to remain consistent between versions of Realm. Any use of this other than manual inspection when debugging is likely to be incorrect.
This is
nil
while the subscription is in the Creating state.Declaration
Objective-C
@property (readonly, nonatomic, nullable) NSString *query;
Swift
var query: String? { get }
-
When this subscription was first created.
This value will be
nil
for subscriptions created with older versions of Realm which did not store the creation date. Newly created subscriptions should always have a non-nil creation date.Declaration
Objective-C
@property (readonly, nonatomic, nullable) NSDate *createdAt;
Swift
var createdAt: Date? { get }
-
When this subscription was last updated.
This value will be
nil
for subscriptions created with older versions of Realm which did not store the update date. Newly created subscriptions should always have a non-nil update date.The update date is the time when the subscription was last updated by a call to
-[RLMResults subscribeWithOptions:]
, and not when the set of objects which match the subscription last changed.Declaration
Objective-C
@property (readonly, nonatomic, nullable) NSDate *updatedAt;
Swift
var updatedAt: Date? { get }
-
When this subscription will be automatically removed.
If the
timeToLive
parameter is set when creating a sync subscription, the subscription will be automatically removed the first time that any subscription is created, modified, or deleted after that time has elapsed.This property will be
nil
if thetimeToLive
option was not enabled.Declaration
Objective-C
@property (readonly, nonatomic, nullable) NSDate *expiresAt;
Swift
var expiresAt: Date? { get }
-
How long this subscription will persist after last being updated.
If the
timeToLive
parameter is set when creating a sync subscription, the subscription will be automatically removed the first time that any subscription is created, modified, or deleted after that time has elapsed.This property will be NaN if the
timeToLive
option was not enabled.Declaration
Objective-C
@property (readonly, nonatomic) NSTimeInterval timeToLive;
Swift
var timeToLive: TimeInterval { get }
-
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.
Unsubscribing is an asynchronous operation and will not immediately remove the subscription from the Realm’s list of subscriptions. Observe the state property to be notified of when the subscription has actually been removed.
Declaration
Objective-C
- (void)unsubscribe;
Swift
func unsubscribe()
-
Unavailable
RLMSyncSubscription cannot be created directly
-[RLMSyncSubscription init]
is not available becauseRLMSyncSubscription
cannot be created directly.Declaration
Objective-C
- (nonnull instancetype)init;
-
Unavailable
RLMSyncSubscription cannot be created directly
+[RLMSyncSubscription new]
is not available becauseRLMSyncSubscription
cannot be created directly.Declaration
Objective-C
+ (nonnull instancetype)new;