SKYRecordStorage

@interface SKYRecordStorage : NSObject

provides a local storage for records that is synchronized with a subset of records on remote server. Changes made remotely are reflected on the local storage and vice versa.

This class is useful for applications in which records are available offline, and that user may modify data when device is offline to have changes uploaded to remote server when device becomes online again.

User should not instantiate an instance of this class directly. An instance of should be obtained from .

  • Returns whether the should synchronizes changes from remote to local and vice versa.

    When this is YES, any pending changes will be performed at an appropriate time. When this is set to NO, any changes will be kept in pending state until this is set to YES again.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL enabled;

    Swift

    var enabled: Bool { get set }
  • Returns whether the is currently updating the backing store.

    When the backing store is being updated, calling -beginUpdating is not allowed.

    Declaration

    Objective-C

    @property (readonly, getter=isUpdating, nonatomic) BOOL updating;

    Swift

    var isUpdating: Bool { get }
  • Returns the backing store object used to initialize the the storage.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic)
        id<SKYRecordStorageBackingStore> _Nonnull backingStore;

    Swift

    var backingStore: SKYRecordStorageBackingStore { get }
  • Sets or returns a synchronizer to the record storage.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic)
        SKYRecordSynchronizer *_Nonnull synchronizer;

    Swift

    var synchronizer: SKYRecordSynchronizer { get set }
  • Returns whether update from remote server is available.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL hasUpdateAvailable;

    Swift

    var hasUpdateAvailable: Bool { get }
  • Undocumented

    Declaration

    Objective-C

    - (instancetype _Nullable)initWithBackingStore:
        (nonnull id<SKYRecordStorageBackingStore>)backingStore;

    Swift

    init?(backingStore: SKYRecordStorageBackingStore)
  • Manually trigger an update to be performed on the receiver.

    Update are performed asynchronously. If there are pending changes, the record storage cannot be updated. This method returns when the receiver cannot perform update.

    Declaration

    Objective-C

    - (void)performUpdateWithCompletionHandler:
        (void (^_Nullable)(BOOL, NSError *_Nullable))completionHandler;

    Swift

    func performUpdate(completionHandler: ((Bool, Error?) -> Void)? = nil)
  • Returns a record from record storage.

    Declaration

    Objective-C

    - (nonnull SKYRecord *)recordWithRecordID:(nonnull SKYRecordID *)recordID;

    Swift

    func record(with recordID: SKYRecordID) -> SKYRecord
  • Returns an array of with the specified type.

    Declaration

    Objective-C

    - (nonnull NSArray *)recordsWithType:(nonnull NSString *)recordType;

    Swift

    func records(withType recordType: String) -> [Any]
  • Returns an array of with the specified type, filtered using the specified predicate.

    Declaration

    Objective-C

    - (nonnull NSArray *)recordsWithType:(nonnull NSString *)recordType
                               predicate:(NSPredicate *_Nullable)predicate
                         sortDescriptors:(NSArray *_Nullable)sortDescriptors;

    Swift

    func records(withType recordType: String, predicate: NSPredicate?, sortDescriptors: [Any]?) -> [Any]
  • Enumerate SKYRecords in the local storage.

    Declaration

    Objective-C

    - (void)enumerateRecordsWithType:(nonnull NSString *)recordType
                           predicate:(NSPredicate *_Nullable)predicate
                     sortDescriptors:(NSArray *_Nullable)sortDescriptors
                          usingBlock:(void (^_Nullable)(SKYRecord *_Nonnull,
                                                        BOOL *_Nonnull))block;

    Swift

    func enumerateRecords(withType recordType: String, predicate: NSPredicate?, sortDescriptors: [Any]?, using block: ((SKYRecord, UnsafeMutablePointer<ObjCBool>) -> Void)? = nil)
  • Returns whether there exists changes in this storage that cannot be synchronized with remote and that the change failed due to a permanent error. A permanent error refers to an error that is likely to reoccur if the change is performed again without modification.

    The application should use this property to detect if there are failed changes in this storage. Failed changes should be acknowledged or resolved.

    @returns YES if there exists failed changes

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL hasFailedChanges;

    Swift

    var hasFailedChanges: Bool { get set }
  • Reutrns whether there exists pending changes in this storage.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL hasPendingChanges;

    Swift

    var hasPendingChanges: Bool { get set }
  • Returns an array of pending record changes.

    Changes are pending when they have not been sent to server for persistence.

    Declaration

    Objective-C

    - (nonnull NSArray *)pendingChanges;

    Swift

    func pendingChanges() -> [Any]
  • Returns an array of failed record changes.

    Changes are failed when persistence result in error from server.

    Declaration

    Objective-C

    - (nonnull NSArray *)failedChanges;

    Swift

    func failedChanges() -> [Any]
  • Undocumented

    Declaration

    Objective-C

    - (nonnull SKYRecordChange *)changeWithRecord:(nonnull SKYRecord *)record;

    Swift

    func change(with record: SKYRecord) -> SKYRecordChange
  • The record state of the given record.

    Declaration

    Objective-C

    - (SKYRecordState)recordStateWithRecord:(nonnull SKYRecord *)record;

    Swift

    func recordState(with record: SKYRecord) -> SKYRecordState
  • Dismisses a record change. Dismissing a change prevents such change from being submitted to the remote server.

    Specifying a change that is currently processed by the remote server will result in an error.

    Declaration

    Objective-C

    - (BOOL)dismissChange:(nonnull SKYRecordChange *)item
                    error:(NSError *_Nullable *_Nullable)error;

    Swift

    func dismiss(_ item: SKYRecordChange) throws
  • Returns a dictionary of modified attributes that will be saved to remote server.

    For each entry in the dictionary, the key is the key of the attribute that is changed with an array containing both the old and new value of the attribute. The object at index 0 correspond to the old value while the object at index 1 correspond to the new value.

    Declaration

    Objective-C

    - (nonnull NSDictionary *)attributesToSaveWithRecord:
        (nonnull SKYRecord *)record;

    Swift

    func attributesToSave(with record: SKYRecord) -> [AnyHashable : Any]
  • Handle failed changes.

    will call the specified block for each failed record.

    Declaration

    Objective-C

    - (void)dismissFailedChangesWithBlock:
        (BOOL (^_Nullable)(SKYRecordChange *_Nonnull, SKYRecord *_Nonnull))block;

    Swift

    func dismissFailedChanges(block: ((SKYRecordChange, SKYRecord) -> Bool)? = nil)
  • Notifies the storage that it will begin receiving record updates.

    Declaration

    Objective-C

    - (void)beginUpdating;

    Swift

    func beginUpdating()
  • Undocumented

    Declaration

    Objective-C

    - (void)beginUpdatingForChanges:(BOOL)forChanges;

    Swift

    func beginUpdating(forChanges: Bool)
  • Notifies the storage that it has received all record updates.

    Call this method when the you have finished sending remote record updates to the storage. The storage uses this opportunity to commit updates to backing store and fires notification that the storage is updated.

    Declaration

    Objective-C

    - (void)finishUpdating;

    Swift

    func finishUpdating()
  • Replace all existing records in the backing store with a new array of records.

    Declaration

    Objective-C

    - (void)updateByReplacingWithRecords:(nonnull NSArray *)records;

    Swift

    func updateByReplacing(withRecords records: [Any])
  • Apply a pending change to the backing store.

    Declaration

    Objective-C

    - (void)updateByApplyingChange:(nonnull SKYRecordChange *)change
                    recordOnRemote:(SKYRecord *_Nullable)remoteRecord
                             error:(NSError *_Nullable)error;

    Swift

    func update(byApplying change: SKYRecordChange, recordOnRemote remoteRecord: SKYRecord?, error: Error?)