KeyValueStoreProtocol
public protocol KeyValueStoreProtocol
KeyValueStore API.
-
Inserts a
SQLiteDatatypeBridgeable
compliant value into the mapping, replacing any existing value for the given key.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func put<T>(_ value: T?, forKey key: String) throws where T : SQLiteDatatypeBridgeable
Parameters
key
a String
value
has to be a
SQLiteDatatypeBridgeable
compliant object -
Inserts a
NSCoding
compliant value into the mapping, replacing any existing value for the given key.Note
This method serializes the value before it is inserted into the underlying store. Therefore, the values must be read with the
get<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?
.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func put<T>(_ value: T?, forKey key: String) throws where T : NSCoding
Parameters
key
a String
value
has to be a
NSCoding
compliant 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
SecureKeyValueStoreProtocol
compliant object once for each mapping from key k to value v in the specified map.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func putAll(_ keyValueDict: [String : NSCoding?]) throws
Parameters
keyValueDict
mappings to be stored
-
Returns the
NSCoding
compliant value to which the specified key is mapped, ornil
if no mapping for this key exists.Note
This method deserializes the value when it is read from the underlying store. Therefore, the values must have been set with the
put(value: NSCoding?, forKey key: String) throws
method 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
.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func get<T>(_ key: String) throws -> T? where T : NSCoding
Return Value
the value as decoded value or
nil
. -
Returns the
SQLiteDatatypeBridgeable
compliant value to which the specified key is mapped, ornil
if no mapping for this key exists.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func get<T>(_ key: String) throws -> T? where T : SQLiteDatatypeBridgeable
Return Value
the value as decoded value or
nil
. -
Returns the
String
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getString(_ key: String) throws -> String?
Parameters
key
a String
Return Value
a String value or
nil
-
Returns the
Int8
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getInt8(_ key: String) throws -> Int8?
Parameters
key
a String
Return Value
an
Int8
value ornil
-
Returns the
Int16
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getInt16(_ key: String) throws -> Int16?
Parameters
key
a String
Return Value
an
Int16
value ornil
-
Returns the
Int32
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getInt32(_ key: String) throws -> Int32?
Parameters
key
a String
Return Value
an
Int32
value ornil
-
Returns the
Int64
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getInt64(_ key: String) throws -> Int64?
Parameters
key
a String
Return Value
an
Int64
value ornil
-
Returns the
Int
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getInt(_ key: String) throws -> Int?
Parameters
key
a String
Return Value
an
Int
value ornil
-
Returns the
UInt8
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getUInt8(_ key: String) throws -> UInt8?
Parameters
key
a String
Return Value
an
UInt8
value ornil
-
Returns the UInt16 value associated with the given key, or
nil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getUInt16(_ key: String) throws -> UInt16?
Parameters
key
a String
Return Value
an
UInt16
value ornil
-
Returns the
UInt32
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getUInt32(_ key: String) throws -> UInt32?
Parameters
key
a String
Return Value
an
UInt32
value ornil
-
Returns the
UInt64
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getUInt64(_ key: String) throws -> UInt64?
Parameters
key
a String
Return Value
an
UInt64
value ornil
-
Returns the
UInt
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getUInt(_ key: String) throws -> UInt?
Parameters
key
a String
Return Value
an
Int
value ornil
-
Returns the
Float
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getFloat(_ key: String) throws -> Float?
Parameters
key
a String
Return Value
a
Float
value ornil
-
Returns the
Double
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getDouble(_ key: String) throws -> Double?
Parameters
key
a String
Return Value
a
Double
value ornil
-
Returns the
Bool
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Note
Conversions between different types of numbers may produce erroneous results. Such as putting an
Int64.max
for 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.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getBool(_ key: String) throws -> Bool?
Parameters
key
a String
Return Value
a
Bool
value ornil
-
Returns the
NSData
value associated with the given key, ornil
if no mapping of the desired type exists for the given key or anil
value is explicitly associated with the key.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func getData(_ key: String) throws -> Data?
Parameters
key
a String
Return Value
a
NSData
value ornil
-
Returns the
SQLiteDatatypeBridgeable
compliant value associated with the given key, ordefaultValue
if no mapping of the desired type exists for the given key or if anil
value is explicitly associated with the given key.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func get<T>(_ key: String, defaultValue: T?) throws -> T? where T : SQLiteDatatypeBridgeable
Parameters
key
a String.
defaultValue
returned if key does not exist or if a
nil
value is associated with the given key.Return Value
the decoded value associated with the given key, or
defaultValue
if no valid object is currently mapped to that key. -
Returns the
NSCoding
compliant value associated with the given key, ordefaultValue
if no mapping of the desired type exists for the given key or if anil
value is explicitly associated with the given key.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.TypeConversionFailed
if the value could not be decoded to the desired return type.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func get<T>(_ key: String, defaultValue: T?) throws -> T? where T : NSCoding
Parameters
key
a String.
defaultValue
returned if key does not exist or if a
nil
value is associated with the given key.Return Value
the decoded value associated with the given key, or
defaultValue
if no valid object is currently mapped to that key.
-
Returns a Set containing the Strings used as keys in this
SecureKeyValueStore
.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func keys() throws -> Set<String>
Return Value
a
Set
of keys. -
Returns whether the given key is contained in the mapping of this
SecureKeyValueStore
.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func hasKey(_ key: String) throws -> Bool
Parameters
key
a String.
Return Value
true
if the key is part of the mapping,false
otherwise
-
Returns the number of mappings contained in this
SecureKeyValueStoreProtocol
compliant object.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func count() throws -> Int
Return Value
the number of mappings as an Int.
-
Returns whether the mapping of this
SecureKeyValueStoreProtocol
compliant object is empty.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func isEmpty() throws -> Bool
Return Value
true
if the mapping of this SecureKeyValueStore is empty,false
otherwise.
-
Removes the entry with the given key from the mapping of this
SecureKeyValueStoreProtocol
compliant object.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
@discardableResult func remove(_ key: String) throws -> Bool
Parameters
key
a String.
Return Value
true
if the key entry was successfully removed,false
if no mapping for the key exists. -
Removes all elements from the mapping of this
SecureKeyValueStoreProtocol
compliant object.Throws
SecureStorageError.Closed
if theSecureKeyValueStoreProtocol
compliant object is locked with its encryption key.Throws
SecureStorageError.BackingStoreError
if an error occured on the underlying store. Code corresponds to sqlite3 error codes (https://www.sqlite.org/c3ref/c_abort.html).Declaration
Swift
func removeAll() throws