views:

28

answers:

1

Hey guys,

My code is as follows:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:YES], @"show_outer_reference_circle_preference",
                                 [NSNumber numberWithBool:YES], @"show_seconds_circle_preference",
                                 nil];

    NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
    [prefs registerDefaults:appDefaults];

    [glView startAnimation];
    return YES;
}

and further down I poll NSUserDefaults with code as follows:

    NSUserDefaults * userDefaults = [[NSUserDefaults standardUserDefaults] retain]; 
    NSNumber* optionsBoolValue = [userDefaults objectForKey:@"show_outer_reference_circle_preference"];
    NSAssert(optionsBoolValue != nil, @"AAAAHH");
    //...
    [userDefaults release];

And the settings don't come through. As you can see, I set the value to YES, buuuuttt the setting comes through as nil and the app goes like "AAAAHH".

What am I doing wrong?

Thanks in advance,

-Nick

A: 

The first part of the code is, as you can see, right after didFinishLaunching. However, the "read-out" part of the code, the second block in the question, is in the init method of an object that is created as a result from loading a nib, and therefore is executed before didFinishLaunching, therefore going like "AAAAHHH".

To correct this, I created an object with one static method for setting the userDefaults, and calling that right before I read any setting.

Nick

related questions