Last active
December 18, 2015 11:19
-
-
Save markd2/5774591 to your computer and use it in GitHub Desktop.
NSUserDefaults and unexpected classes. Make sure #define BREAKS is 1 Then: % ./defaults-death 2013-06-11 15:50:13.811 defaults-death[48089:303] thing is WAFFLE % defaults write defaults-death spoon -string badger % ./defaults-death 2013-06-11 15:51:01.548 defaults-death[48121:303] thing is BADGER % defaults write defaults-death spoon -integer 23…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -g -Wall -framework Foundation -o defaults-death defaults-death.m | |
int main (void) { | |
@autoreleasepool { | |
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; | |
NSDictionary *defaultDefaults = @{ | |
@"spoon" : @"waffle" | |
}; | |
[defs registerDefaults: defaultDefaults]; | |
// Now do stuff | |
NSString *thing = [defs objectForKey: @"spoon"]; | |
#define BREAKS 1 | |
#if BREAKS | |
NSLog (@"thing is %@", [thing uppercaseString]); | |
#else | |
if ([thing isKindOfClass: [NSString class]]) { | |
NSLog (@"thing is %@", [thing uppercaseString]); | |
} else { | |
NSLog (@"bad defaults, man!"); | |
} | |
#endif | |
} | |
return 0; | |
} // main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment