Skip to content

Instantly share code, notes, and snippets.

@markd2 markd2/gist:5774591
Last active Dec 18, 2015

What would you like to do?
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…
#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
NSLog (@"thing is %@", [thing uppercaseString]);
if ([thing isKindOfClass: [NSString class]]) {
NSLog (@"thing is %@", [thing uppercaseString]);
} else {
NSLog (@"bad defaults, man!");
return 0;
} // main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.