clear() method added

This commit is contained in:
Vladimir Enchev
2016-02-23 17:44:06 +02:00
parent 3d0bf74999
commit c323201e52
4 changed files with 26 additions and 0 deletions

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);