UNPKG

2.07 kBJavaScriptView Raw
1import * as Common from './application-settings-common';
2import * as utils from '../utils';
3const userDefaults = NSUserDefaults.standardUserDefaults;
4export function hasKey(key) {
5 if (!Common.checkKey(key)) {
6 return;
7 }
8 return userDefaults.objectForKey(key) !== null;
9}
10// utils.ios.getters
11export function getBoolean(key, defaultValue) {
12 if (!Common.checkKey(key)) {
13 return;
14 }
15 if (hasKey(key)) {
16 return userDefaults.boolForKey(key);
17 }
18 return defaultValue;
19}
20export function getString(key, defaultValue) {
21 if (!Common.checkKey(key)) {
22 return;
23 }
24 if (hasKey(key)) {
25 return userDefaults.stringForKey(key);
26 }
27 return defaultValue;
28}
29export function getNumber(key, defaultValue) {
30 if (!Common.checkKey(key)) {
31 return;
32 }
33 if (hasKey(key)) {
34 return userDefaults.doubleForKey(key);
35 }
36 return defaultValue;
37}
38// setters
39export function setBoolean(key, value) {
40 if (!Common.checkKey(key)) {
41 return;
42 }
43 if (!Common.ensureValidValue(value, 'boolean')) {
44 return;
45 }
46 userDefaults.setBoolForKey(value, key);
47}
48export function setString(key, value) {
49 if (!Common.checkKey(key)) {
50 return;
51 }
52 if (!Common.ensureValidValue(value, 'string')) {
53 return;
54 }
55 userDefaults.setObjectForKey(value, key);
56}
57export function setNumber(key, value) {
58 if (!Common.checkKey(key)) {
59 return;
60 }
61 if (!Common.ensureValidValue(value, 'number')) {
62 return;
63 }
64 userDefaults.setDoubleForKey(value, key);
65}
66export function remove(key) {
67 if (!Common.checkKey(key)) {
68 return;
69 }
70 userDefaults.removeObjectForKey(key);
71}
72export function clear() {
73 userDefaults.removePersistentDomainForName(NSBundle.mainBundle.bundleIdentifier);
74}
75export function flush() {
76 return userDefaults.synchronize();
77}
78export function getAllKeys() {
79 return utils.ios.collections.nsArrayToJSArray(userDefaults.dictionaryRepresentation().allKeys);
80}
81//# sourceMappingURL=index.ios.js.map
\No newline at end of file