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
| Platform | Backend |
|---|---|
| macOS | NSUserDefaults |
| iOS | NSUserDefaults |
| Android | SharedPreferences |
| Windows | Windows Registry |
| Linux | GSettings / file-based |
| Web | localStorage |
Preferences persist across app launches. They are not encrypted — use Keychain for sensitive data.