SecureKeyValueStore
open class SecureKeyValueStore : KeyValueStoreProtocol
extension SecureKeyValueStore: DataStoring
Secure Key-Value Store
Similar to the SecureDatabaseStore, you can create instances of the SecureKeyValueStore as follows.
let secureKeyValueStore = SecureKeyValueStore()
try secureKeyValueStore.open(with: "your_encryption_key")
It is also possible to create more SecureKeyValueStores sharing the same database file. In this can specify a separate name for the store.
Shared the same database is not thread safe. It is the task of the caller to make it thread safe.
// it is advisable to name all the stores if multiple store used in one file
let firstStore = SecureKeyValueStore(name:"FirstStore")
var secondStore = SecureKeyValueStore()
do {
// initialization throws only when the firstStore is open already
try SecureKeyValueStore(databaseStore: firstStore.secureDatabaseStore, name:"secondKeyValueStore")
} catch {
// handle error
return
}
// open one of the stores
do {
try firstStore.open(with: "any passcode")
} catch {
// handle error
return
}
Since the init of the store will throw only when the first database is already open and there isn’t schema created already and the schema creation fails it is possible to create the store with try! Simplified form:
let firstStore = SecureKeyValueStore(name:"FirstStore")
let secondStore = try! SecureKeyValueStore(databaseStore: firstStore.secureDatabaseStore, name:"secondKeyValueStore")
// open one of the stores
do {
try firstStore.open(with: "any passcode")
} catch {
// handle error
return
}
-
secureDatabaseStore instance
Declaration
Swift
public let secureDatabaseStore: SecureDatabaseStore -
default filename for database
Declaration
Swift
public static let defaultDatabaseFileName: String -
the name of the KeyValueStore
Declaration
Swift
open var storeName: String
-
Initialize a new
SecureKeyValueStorein the default location with the specified or default database file name.Declaration
Swift
public convenience init(databaseFileName: String = defaultDatabaseFileName, name: String = SecureStoreDefaultStoreName)Parameters
databaseFileNamea database file name with a default value
namethe name of the KeyValueStore - used to create a separate Database table in the
SecureDatabaseStore -
Initialize a new
SecureDatabaseStorein the specified path.Declaration
Swift
public convenience init(fullDatabasePath: String, name: String = SecureStoreDefaultStoreName)Parameters
fullDatabasePatha full path of the database file name
storeNamethe name of the KeyValueStore - used to create a separate Database table in the
SecureDatabaseStore -
Initializes a store using an other existing store. This way the same database file will be used. Make sure to use unique names for the stores. The name given will be used to create a separate table so use only characters allowed to create a table name. If the
databaseStorealready exists the init tries to create the table for this store if it doesn’t exist already. If this creation fails the init fails. If thedatabaseStoreis not open the init will never fail. The table for the store will be created during theopenof the hostdatabaseStore. If the table creation fails during the open, the open method will fail and the database remains closed.Declaration
Swift
public convenience init(databaseStore: SecureDatabaseStore, name: String = SecureStoreDefaultStoreName) throwsParameters
databaseStorean existing store
nameunique name of the store in this database
-
Opens the
SecureStorewith the respective encryption key. This call sets the encryption key of a store if the store is opened for the first time and if data is written afterwards. The underlying store is opened for read and write access and it is created at the specified path if it does not already exist.Throws
SecureStorageError.AuthenticationFailedif an error occured while setting the encryption key and if the encyption key is wrong or an empty string.Throws
SecureStorageError.OpenFailedif something went wrong while opening and/or creating the store. Error codes correspond to sqlite3 error codes if the underlying store is a sqlite database (see https://www.sqlite.org/c3ref/c_abort.html).Note
Please make sure to set thedelegatebefore you callopen(with encryptionKey: String)if you want to receive thedidCreateStorecallback.Note
The actual database encryption key is drived from the StringencryptionKeywith PBKDF2.Note
In case the store is already opened the method doesn’t have any effect and it won’t validate the passcode.Declaration
Swift
open func open(with encryptionKey: String) throwsParameters
encryptionKeythe secure store’s encryption key as String.
-
Opens the
SecureStorewith the respective encryption key. The underlying store is opened for read and write access. The store at the specified path is created if it does not exist.Throws
SecureStorageError.AuthenticationFailedif an error occured while setting the encryption key and if the encyption key is wrong or an empty string.Throws
SecureStorageError.OpenFailedif something went wrong while opening and/or creating the store. Error codes correspond to sqlite3 error codes if the underlying store is a sqlite database (see https://www.sqlite.org/c3ref/c_abort.html).Warning
The binaryencryptionKeyDatadata is used directly as the database encryption key. The must be exactly 256 bit in length.Note
Please make sure to set thedelegatebefore you callopen(with encryptionKey: Data)if you want to receive thedidCreateStorecallback.Declaration
Swift
open func open(with encryptionKeyData: Data) throwsParameters
ecryptionKeyDatathe secure store’s binary encryption key as Data. It must be exactly 256 bit in length.
-
Checks whether the store is open.
Declaration
Swift
open func isOpen() -> BoolReturn Value
trueif the store is open,falseotherwise. -
Closes the store and therefore the
SecureStoreis no longer accessible without opening it again with its encryption key.Declaration
Swift
open func close()
-
Changes the encryption key of the
SecureStoreif it has been opened. OtherwiseSecureStorageError.Closedis thrown and the encryption key remains unchanged.Changing the key means re-encryption of the whole database which can take a long time on larger databases.
Throws
SecureStorageError.Closedif the store is locked with its encryption key.Throws
SecureStorageError.EncryptionKeyChangeFailedif an error occured while changing the encryption key.Declaration
Swift
open func changeEncryptionKey(with newEncryptionKey: String) throwsParameters
newEncryptionKeythe
SecureStore’s new encryption key as String. -
Changes the encryption key of the
SecureStoreif it has been opened. OtherwiseSecureStorageError.Closedis thrown and the encryption key remains unchanged.Changing the key means re-encryption of the whole database which can take a long time on larger databases.
Throws
SecureStorageError.Closedif the store is locked with its encryption key.Throws
SecureStorageError.EncryptionKeyChangeFailedif an error occured while changing the encryption key.Declaration
Swift
open func changeEncryptionKey(with newEncryptionKeyData: Data) throwsParameters
newEncryptionKeyDatathe
SecureStore’s new encryption key.
-
Inserts a
SQLiteDatatypeBridgeablecompliant value into the mapping, replacing any existing value for the given key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func put<T>(_ value: T?, forKey key: String) throws where T : SQLiteDatatypeBridgeableParameters
keya String
valuehas to be a
SQLiteDatatypeBridgeablecompliant object -
Inserts a
NSCodingcompliant value into the mapping, replacing any existing value for the given key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
This method serializes the value before it is inserted into the underlying store. Therefore, the values must be read with theget<T: NSCoding>(_ key: String) throws -> T?in order to deserialize them properly. It is not possible to read values with specific get methods likegetString(key: String) throws -> String?.Declaration
Swift
open func put<T>(_ value: T?, forKey key: String) throws where T : NSCodingParameters
keya String
valuehas to be a
NSCodingcompliant object -
Associates all specified values with their respective key. The effect of this call is equivalent to that of calling put(k, v) on this SecureKeyValueStore once for each mapping from key k to value v in the specified map.
Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func putAll(_ keyValueDict: [String : NSCoding?]) throwsParameters
keyValueDictmappings to be stored
-
Returns the
SQLiteDatatypeBridgeablecompliant value to which the specified key is mapped, ornilif no mapping for this key exists.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func get<T>(_ key: String) throws -> T? where T : SQLiteDatatypeBridgeableParameters
keya String.
Return Value
the value as decoded value or
nil. -
Returns the
NSCodingcompliant value to which the specified key is mapped, ornilif no mapping for this key exists.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Note
This method deserializes the value when it is read from the underlying store. Therefore, the values must have been set with theput(value: NSCoding?, forKey key: String) throwsmethod in order to be serialized properly. It is not possible to read values with this method that have been set with the specific put methods likeputString(value: String?, forKey key: String) throws.Declaration
Swift
open func get<T>(_ key: String) throws -> T? where T : NSCodingParameters
keya String.
Return Value
the value as decoded value or
nil. -
Returns the
Stringvalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func getString(_ key: String) throws -> String?Parameters
keya String
Return Value
a String value or
nil -
Returns the
Int8value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getInt8(_ key: String) throws -> Int8?Parameters
keya String
Return Value
an
Int8value ornil -
Returns the
Int16value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getInt16(_ key: String) throws -> Int16?Parameters
keya String
Return Value
an
Int16value ornil -
Returns the
Int32value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getInt32(_ key: String) throws -> Int32?Parameters
keya String
Return Value
an
Int32value ornil -
Returns the
Int64value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getInt64(_ key: String) throws -> Int64?Parameters
keya String
Return Value
an
Int64value ornil -
Returns the
Intvalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getInt(_ key: String) throws -> Int?Parameters
keya String
Return Value
an
Intvalue ornil -
Returns the
UInt8value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getUInt8(_ key: String) throws -> UInt8?Parameters
keya String
Return Value
an
UInt8value ornil -
Returns the UInt16 value associated with the given key, or
nilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getUInt16(_ key: String) throws -> UInt16?Parameters
keya String
Return Value
an
UInt16value ornil -
Returns the
UInt32value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getUInt32(_ key: String) throws -> UInt32?Parameters
keya String
Return Value
an
UInt32value ornil -
Returns the
UInt64value associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getUInt64(_ key: String) throws -> UInt64?Parameters
keya String
Return Value
an
UInt64value ornil -
Returns the
UIntvalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getUInt(_ key: String) throws -> UInt?Parameters
keya String
Return Value
an
UIntvalue ornil -
Returns the
Floatvalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getFloat(_ key: String) throws -> Float?Parameters
keya String
Return Value
a
Floatvalue ornil -
Returns the
Doublevalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getDouble(_ key: String) throws -> Double?Parameters
keya String
Return Value
a
Doublevalue ornil -
Returns the
Boolvalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Note
Conversions between different types of numbers may produce erroneous results. Such as putting anInt64.maxfor a specific key and getting this value withtype: Int8. Conversions are handled in accordance to the behaviour ofNSNumber. Further information can be found at https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/index.html.Declaration
Swift
open func getBool(_ key: String) throws -> Bool?Parameters
keya String
Return Value
a
Boolvalue ornil -
Returns the
NSDatavalue associated with the given key, ornilif no mapping of the desired type exists for the given key or anilvalue is explicitly associated with the key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func getData(_ key: String) throws -> Data?Parameters
keya String
Return Value
a
NSDatavalue ornil -
MARK: - Getting Values with Default Value Returns the
NSCodingcompliant value associated with the given key, ordefaultValueif no mapping of the desired type exists for the given key or if anilvalue is explicitly associated with the given key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func get<T>(_ key: String, defaultValue: T?) throws -> T? where T : NSCodingParameters
keya String.
defaultValuereturned if key does not exist or if a
nilvalue is associated with the given key.Return Value
the decoded value associated with the given key, or
defaultValueif no valid object is currently mapped to that key.
-
Returns the
SQLiteDatatypeBridgeablecompliant value associated with the given key, ordefaultValueif no mapping of the desired type exists for the given key or if anilvalue is explicitly associated with the given key.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func get<T>(_ key: String, defaultValue: T?) throws -> T? where T : SQLiteDatatypeBridgeableParameters
keya String.
defaultValuereturned if key does not exist or if a
nilvalue is associated with the given key.Return Value
the decoded value associated with the given key, or
defaultValueif no valid object is currently mapped to that key.
-
Returns a Set containing the Strings used as keys in this
SecureKeyValueStore.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func keys() throws -> Set<String>Return Value
a
Setof keys. -
Returns whether the given key is contained in the mapping of this
SecureKeyValueStore.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func hasKey(_ key: String) throws -> BoolParameters
keya String.
Return Value
trueif the key is part of the mapping,falseotherwise
-
Returns the number of mappings contained in this
SecureKeyValueStore.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func count() throws -> IntReturn Value
the number of mappings as an Int.
-
Returns whether the mapping of this
SecureKeyValueStoreis empty.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func isEmpty() throws -> BoolReturn Value
trueif the mapping of this SecureKeyValueStore is empty,falseotherwise.
-
Removes the entry with the given key from the mapping of this
SecureKeyValueStore.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
@discardableResult open func remove(_ key: String) throws -> BoolParameters
keya String.
Return Value
trueif the key entry was successfully removed,falseif no mapping for the key exists. -
Removes all elements from the mapping of this
SecureKeyValueStore.Throws
SecureStorageError.Closedif the SecureKeyValueStore is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
open func removeAll() throws -
Implementation for DataStoring protocol’s put function
Throws
SecureStorageError.Closedif theDataStoringcompliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
public func put(data: Data, for key: String) throwsParameters
datadata to put in the storage
keya String which will be the key for the data in the storage
-
Implementation for DataStoring protocol’s data(for:) function
Throws
SecureStorageError.Closedif theDataStoringcompliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailedif the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
public func data(for key: String) throws -> Data?Parameters
keya String
Return Value
Data if there is data for the key, or nil if not found
-
Implementation for DataStoring protocol’s removeData(for:) function
Throws
SecureStorageError.Closedif theDataStoringcompliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreErrorif an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
public func removeData(for key: String) throwsParameters
keya String to find data in the storage