mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
clear() method added
This commit is contained in:
@ -74,3 +74,8 @@ export var remove = function (key: string): void {
|
||||
editor.remove(key);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
export var clear = function (): void {
|
||||
ensureSharedPreferences();
|
||||
sharedPreferences.edit().clear().commit();
|
||||
}
|
||||
|
@ -55,4 +55,9 @@ declare module "application-settings" {
|
||||
* @param key The key to check for.
|
||||
*/
|
||||
export function remove(key: string): void;
|
||||
|
||||
/**
|
||||
* Removes all values.
|
||||
*/
|
||||
export function clear(): void;
|
||||
}
|
@ -59,3 +59,7 @@ export var remove = function (key: string): void {
|
||||
userDefaults.removeObjectForKey(key);
|
||||
userDefaults.synchronize();
|
||||
}
|
||||
|
||||
export var clear = function (): void {
|
||||
userDefaults.removePersistentDomainForName(NSBundle.mainBundle().bundleIdentifier);
|
||||
}
|
||||
|
@ -123,6 +123,18 @@ export var testRemove = function () {
|
||||
TKUnit.assert(!appSettings.hasKey(numberKey), "Failed to remove key: " + numberKey);
|
||||
};
|
||||
|
||||
export var testClear = function () {
|
||||
// <snippet module="application-settings" title="application-settings">
|
||||
// ### Removing all values
|
||||
// ``` JavaScript
|
||||
appSettings.clear();
|
||||
// ```
|
||||
// </snippet>
|
||||
TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey);
|
||||
TKUnit.assert(!appSettings.hasKey(stringKey), "Failed to remove key: " + stringKey);
|
||||
TKUnit.assert(!appSettings.hasKey(numberKey), "Failed to remove key: " + numberKey);
|
||||
};
|
||||
|
||||
export var testInvalidKey = function () {
|
||||
try {
|
||||
appSettings.hasKey(undefined);
|
||||
|
Reference in New Issue
Block a user