mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Merge pull request #138 from triplef/fix-nsuserdefaults-setbool
Store NSNumber instead of NSString for NSUserDefaults -setBool:forKey:.
This commit is contained in:
commit
a636994a33
3 changed files with 23 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
|||
2020-05-25 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Source/NSUserDefaults.m:
|
||||
Store NSNumber instead of NSString for NSUserDefaults -setBool:forKey:.
|
||||
|
||||
2020-05-14 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Headers/Foundation/NSException.h:
|
||||
|
|
|
@ -1420,14 +1420,9 @@ newLanguages(NSArray *oldNames)
|
|||
|
||||
- (void) setBool: (BOOL)value forKey: (NSString*)defaultName
|
||||
{
|
||||
if (value == YES)
|
||||
{
|
||||
[self setObject: @"YES" forKey: defaultName];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setObject: @"NO" forKey: defaultName];
|
||||
}
|
||||
NSNumber *n = [NSNumberClass numberWithBool: value];
|
||||
|
||||
[self setObject: n forKey: defaultName];
|
||||
}
|
||||
|
||||
- (void) setDouble: (double)value forKey: (NSString*)defaultName
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSNotification.h>
|
||||
#import <Foundation/NSUserDefaults.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
@interface Observer : NSObject
|
||||
|
@ -40,27 +42,39 @@ int main()
|
|||
[defs setBool: YES forKey: @"Test Suite Bool"];
|
||||
PASS([defs boolForKey: @"Test Suite Bool"],
|
||||
"NSUserDefaults can set/get a BOOL");
|
||||
PASS([[defs objectForKey: @"Test Suite Bool"] isKindOfClass:[NSNumber class]],
|
||||
"NSUserDefaults returns NSNumber for a BOOL");
|
||||
|
||||
PASS_EQUAL([obs count], @"1", "setting a boolean causes notification");
|
||||
|
||||
[defs setInteger: 34 forKey: @"Test Suite Int"];
|
||||
PASS([defs integerForKey: @"Test Suite Int"] == 34,
|
||||
"NSUserDefaults can set/get an int");
|
||||
PASS([[defs objectForKey: @"Test Suite Int"] isKindOfClass:[NSNumber class]],
|
||||
"NSUserDefaults returns NSNumber for an int");
|
||||
|
||||
PASS_EQUAL([obs count], @"2", "setting an integer causes notification");
|
||||
|
||||
[defs setObject: @"SetString" forKey: @"Test Suite Str"];
|
||||
PASS([[defs stringForKey: @"Test Suite Str"] isEqual: @"SetString"],
|
||||
"NSUserDefaults can set/get a string");
|
||||
|
||||
PASS([[defs objectForKey: @"Test Suite Str"] isKindOfClass:[NSString class]],
|
||||
"NSUserDefaults returns NSString for a string");
|
||||
|
||||
PASS_EQUAL([obs count], @"3", "setting a string causes notification");
|
||||
|
||||
[defs removeObjectForKey: @"Test Suite Bool"];
|
||||
PASS(nil == [defs objectForKey: @"Test Suite Bool"],
|
||||
"NSUserDefaults can use -removeObjectForKey: to remove a bool");
|
||||
|
||||
PASS_EQUAL([obs count], @"4", "removing a key causes notification");
|
||||
|
||||
[defs setObject: nil forKey: @"Test Suite Int"];
|
||||
PASS(nil == [defs objectForKey: @"Test Suite Int"],
|
||||
"NSUserDefaults can use -setObject:forKey: to remove an int");
|
||||
|
||||
PASS_EQUAL([obs count], @"5", "setting nil object causes notification");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue