get

inline fun <T : Any> MMKV.get(key: String, default: T): T

Type-safe inline convenience for get using reified type T.

Return

The decoded value as T, or default when absent.

Parameters

key

The key to read.

default

The value to return when the key does not exist or the buffer is empty.


inline fun <T : Any> MMKV.get(key: String): T?

Type-safe inline convenience for get using reified type T.

Return

The decoded value as T, or null when absent.

Parameters

key

The key to read.


fun <T : Any> MMKV.get(key: String, clazz: KClass<T>, default: T? = null): T?

Reads a value from MMKV and decodes it as the given Kotlin class clazz.

Supported types: Int, Long, Float, Double, Boolean, String, List, Iterable, ByteArray. Values are stored as tagged binary buffers by this extension layer.

Return

The decoded value cast to T, or default when absent.

Parameters

key

The key to read.

clazz

The expected Kotlin class of the value.

default

The value to return when the key does not exist or the buffer is empty.

Throws

if the stored buffer tag doesn't match clazz or type unsupported.