Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Preferences

Store and retrieve user preferences using the platform’s native storage. Every snippet below is excerpted from docs/examples/system/snippets.ts — CI links it on every PR.

Usage

preferencesSet(key, value) accepts strings or numbers and round-trips them natively (NSUserDefaults / GSettings / Registry preserve the original type). preferencesGet(key) returns string | number | undefined:

// Strings and numbers round-trip natively — no manual stringification needed.
preferencesSet("theme", "dark")
preferencesSet("font-size", 14)

const theme = preferencesGet("theme")        // string | number | undefined
const fontSize = preferencesGet("font-size") // → 14 (number)

if (typeof theme === "string") {
    console.log(`saved theme: ${theme}`)
}
if (typeof fontSize === "number") {
    console.log(`saved font-size: ${fontSize}`)
}

Platform Storage

PlatformBackend
macOSNSUserDefaults
iOSNSUserDefaults
AndroidSharedPreferences
WindowsWindows Registry
LinuxGSettings / file-based
WeblocalStorage

Preferences persist across app launches. They are not encrypted — use Keychain for sensitive data.

Next Steps