UXKVEntry
UXKVEntry is one entry in a
UXKeyValueStore’s cache.
#use <UXKit> // or #import "UXKeyValueStore.xc"Overview
Section titled “Overview”class UXKVEntry : Object { u8* key; i32 type; // UXKV_STRING / UXKV_INT / UXKV_BOOL u8* str; // when type is STRING i32 num; // when type is INT or BOOL}One class holds three types, and type says which field is live. A bool is
stored in num rather than in a field of its own, as an integer with a
narrower range.
It is cache, not storage
Section titled “It is cache, not storage”The entry is a copy of what the persistent store holds, kept so a repeated
read costs nothing. The value itself lives wherever the platform keeps
preferences: the system registry on XTOS, NSUserDefaults on macOS, an .ini
under %APPDATA% on Windows.
For this reason
invalidate exists, and
another process writing the same key mid-run
is not seen.
An entry tells you what this process last knew, not what is on disk now.
Registered defaults are entries too
Section titled “Registered defaults are entries too”A registration and a set value are both entries, so
hasKey cannot test only
whether an entry exists. The store tracks the distinction separately, so that
removeKey can revert to the registration rather than deleting it.
A UXKVEntry means the store has an answer for this key, not the user
chose it.
Type is not enforced on read
Section titled “Type is not enforced on read”Reading a key with the wrong accessor returns the field that accessor uses,
whatever type says. An intFor on a string entry reads num, which the
string path never filled in.
The type is normally fixed by the code that registers the default at startup, so this only goes wrong through the app’s own mistake. It matters if you change a setting’s type between versions: the stored value does not migrate, and the old value is read through the new accessor.
Fields
Section titled “Fields”u8* keyi32 type // UXKV_STRING, UXKV_INT, UXKV_BOOLu8* strAlways a copy the store made. Settings come back through a shared scratch
buffer that the next call overwrites, so the entry duplicates the text on the
way in, using UXStr.dup.
i32 numThe integer, or 0/1 for a bool.
Conforms to
Section titled “Conforms to”- Inherits
Object
See also
Section titled “See also”UXKeyValueStore: the storeUXCacheEntry: the evicting equivalent, with a clock because entries leaveUXViewDriver:settingGet/settingSet