KeychainSettings

class KeychainSettings(defaultProperties: Pair<CFStringRef?, CFTypeRef?>)

A collection of storage-backed key-value data

This class allows storage of values with the Int, Long, String, Float, Double, or Boolean types, using a String reference as a key. Values will be persisted across app launches.

The specific persistence mechanism is defined using a platform-specific implementation, so certain behavior may vary across platforms. In general, updates will be reflected immediately in-memory, but will be persisted to disk asynchronously.

Operator extensions are defined in order to simplify usage. In addition, property delegates are provided for cleaner syntax and better type-safety when interacting with values stored in a Settings instance.

The KeychainSettings implementation saves data to the Apple keychain. Data is saved using the generic password type, where keys are account names and values are treated as passwords. The value passed to the String constructor will be used as the service name. It's also possible to pass custom key-value pairs as attributes that will be added to every key, if the default behavior does not fit your needs.

Constructors

Link copied to clipboard
constructor(service: String)
constructor(vararg defaultProperties: Pair<CFStringRef?, CFTypeRef?>)

Properties

Link copied to clipboard
Link copied to clipboard
val size: Int

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
fun getBoolean(key: String, defaultValue: Boolean): Boolean
Link copied to clipboard
Link copied to clipboard
fun getDouble(key: String, defaultValue: Double): Double
Link copied to clipboard
Link copied to clipboard
fun getFloat(key: String, defaultValue: Float): Float
Link copied to clipboard
Link copied to clipboard
fun getInt(key: String, defaultValue: Int): Int
Link copied to clipboard
fun getIntOrNull(key: String): Int?
Link copied to clipboard
fun getLong(key: String, defaultValue: Long): Long
Link copied to clipboard
Link copied to clipboard
fun getString(key: String, defaultValue: String): String
Link copied to clipboard
Link copied to clipboard
fun hasKey(key: String): Boolean
Link copied to clipboard
fun putBoolean(key: String, value: Boolean)
Link copied to clipboard
fun putDouble(key: String, value: Double)
Link copied to clipboard
fun putFloat(key: String, value: Float)
Link copied to clipboard
fun putInt(key: String, value: Int)
Link copied to clipboard
fun putLong(key: String, value: Long)
Link copied to clipboard
fun putString(key: String, value: String)
Link copied to clipboard
fun remove(key: String)