DataStoreManager
@objcMembers
open class DataStoreManager : NSObject
An interface to the data store manager, where you store key-value pairs persistently across launches of your app.
-
Return a data store manager with the specified identifier.
Initialize a new data store manager object immediately after memory for it has been allocated.
Declaration
Swift
public required init(identifier: String)Parameters
identifierA string identifying the data store manager object.
Return Value
An initialized object, or
nilif an object could not be created for some reason that would not result in an exception.
-
Returns the data store manager framework short version string.
Declaration
Swift
open var version: String? { get } -
Returns the identifier of the data store manager.
Declaration
Swift
open var identifier: String { get } -
An integer that you can use to identify data store manager objects in your application.
The default value is 0. You can set the value of this tag and use that value to identify the data store manager later.
Declaration
Swift
open var tag: Int { get set } -
The object that acts as the data source of the data store manager.
The data source must adopt the DataStoreManagerDataSource protocol. The data source is not retained.
Declaration
Swift
open weak var dataSource: DataStoreManagerDataSource? { get set } -
The object that acts as the delegate of the data store manager.
The delegate must adopt the DataStoreManagerDelegate protocol. The delegate is not retained.
Declaration
Swift
open weak var delegate: DataStoreManagerDelegate? { get set } -
An interface to the UserDefaults.
Declaration
Swift
lazy var userDefaultsWorker: DataStoreManager.UserDefaultsWorker { get set } -
An interface to the FileManager.
Declaration
Swift
lazy var fileManagerWorker: DataStoreManager.FileManagerWorker { get set } -
An interface to the NSCache.
Declaration
Swift
lazy var cacheWorker: DataStoreManager.CacheWorker { get set } -
An interface to the Security.
Declaration
Swift
lazy var keychainWorker: DataStoreManager.KeychainWorker { get set } -
An interface to the CoreData.
Declaration
Swift
lazy var coreDataWorker: DataStoreManager.CoreDataWorker { get set } -
An interface to the CloudKit.
Declaration
Swift
@available(watchOSApplicationExtension 3.0, *) lazy var cloudKitWorker: DataStoreManager.CloudKitWorker { get set } -
An interface to the NSUbiquitousKeyValueStore.
Declaration
Swift
@available(watchOS, unavailable) lazy var ubiquitousCloudStoreWorker: DataStoreManager.UbiquitousCloudStoreWorker { get set }
-
Create the property of the receiver specified by a given key to a given object.
Declaration
Swift
open func create(object: Any, forKey key: String, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
objectThe object for the property identified by key.
keyThe name of one of the receiver’s properties.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Create the property of the receiver specified by a given key to a given object.
Declaration
Swift
open func create(object: Any, forKey key: String, forStorageType storageType: DataStoreStorageType, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
objectThe object for the property identified by key.
keyThe key to identify the data store manager object.
storageTypeA storage type constant.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Returns the object associated with the specified key.
Declaration
Swift
open func read<T>(forKey key: String, withObjectType objectType: T.Type, completionHandler: @escaping (_ object: Any?, _ objectID: Any?, _ error: Error?) -> Void)Parameters
keyThe key to identify the data store manager object.
objectTypeThe type of object for the property identified by key.
completionHandlerThe block to execute with the associated object. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
objectThe object associated with the specified key, or
nilif the key was not found.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Returns the object associated with the specified key.
Declaration
Swift
open func read<T>(forKey key: String, withObjectType objectType: T.Type, forStorageType storageType: DataStoreStorageType, completionHandler: @escaping (_ object: Any?, _ objectID: Any?, _ error: Error?) -> Void)Parameters
keyThe key to identify the data store manager object.
objectTypeThe type of object for the property identified by key.
storageTypeA storage type constant.
completionHandlerThe block to execute with the associated object. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
objectThe object associated with the specified key, or
nilif the key was not found.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Update the property of the receiver specified by a given key to a given object.
Declaration
Swift
open func update(object: Any, forKey key: String, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
objectThe object for the property identified by key.
keyThe name of one of the receiver’s properties.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Update the property of the receiver specified by a given key to a given object.
Declaration
Swift
open func update(object: Any, forKey key: String, forStorageType storageType: DataStoreStorageType, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
objectThe object for the property identified by key.
keyThe key to identify the data store manager object.
storageTypeA storage type constant.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Removes the object of the specified default key.
Declaration
Swift
open func delete<T>(forKey key: String, withObjectType objectType: T.Type, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
keyThe key to identify the data store manager object.
objectTypeThe type of object for the property identified by key.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Removes the object of the specified default key.
Declaration
Swift
open func delete<T>(forKey key: String, withObjectType objectType: T.Type, forStorageType storageType: DataStoreStorageType, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
keyThe key to identify the data store manager object.
objectTypeThe type of object for the property identified by key.
storageTypeA storage type constant.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Empties the data store manager for the given type.
Declaration
Swift
open func deleteAll(completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround. -
Empties the data store manager for the given type.
Declaration
Swift
open func deleteAll(forStorageType storageType: DataStoreStorageType, completionHandler: @escaping (_ isSuccessful: Bool, _ objectID: Any?, _ error: Error?) -> Void)Parameters
storageTypeA storage type constant.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.objectIDThe unique ID of the object. For CloudKit, the type is CKRecord.ID and it is the object that uniquely identifies a record in a database.
errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround.
-
Migrate the schema if the version differs.
Call this function at the point where you app can migrate the schema. It will check first if the schema version is the same or not.If the schema needs to be migrated, it will call dataStoreManager(_:performMigrationFromOldVersion:forType:) delegate method.
Declaration
Swift
open func migrateSchema(forStorageType storageType: DataStoreStorageType, completionHandler: @escaping (_ isSuccessful: Bool, _ error: Error?) -> Void)Parameters
storageTypeA storage type constant.
completionHandlerThe block to execute with the successful flag. This block is executed asynchronously on your app’s main thread. The block has no return value and takes the following parameter:
isSuccessfultrueon successful;falseif not.errorAn error object, or
nilif it was completed successfully. Use the information in the error object to determine whether a problem has a workaround.
-
An interface to the NSCache.
See moreDeclaration
Swift
internal class CacheWorker : NSDiscardableContent
-
An interface to the CloudKit.
See moreDeclaration
Swift
@available(watchOSApplicationExtension 3.0, *) internal class CloudKitWorker
-
An interface to the CoreData.
See moreDeclaration
Swift
internal class CoreDataWorker
-
An interface to the FileManager.
See moreDeclaration
Swift
internal class FileManagerWorker
-
An interface to the Security.
See moreDeclaration
Swift
internal class KeychainWorker
-
An interface to the NSUbiquitousKeyValueStore.
See moreDeclaration
Swift
@available(watchOS, unavailable) internal class UbiquitousCloudStoreWorker
-
An interface to the UserDefaults.
See moreDeclaration
Swift
internal class UserDefaultsWorker
DataStoreManager Class Reference