tags:

views:

135

answers:

2

Hello, I have received an error that indicates that "savedNumberDict" is Out Of Scope. I am not quite sure where to look for a solution. Any suggestions? The code is below that I am using. Thanks.

- (void)applicationDidFinishLaunching:(UIApplication*) application {
    self.savedNumber = [[NSUserDefaults standardUserDefaults]objectForKey:kNumberLocationKey];

    if (savedNumber == nil) {
        savedNumber = @"555 555 1212";
        NSDictionary *savedNumberDict = [NSDictionary dictionaryWithObject:savedNumber forKey:kNumberLocationKey];
        [[NSUserDefaults standardUserDefaults] registerDefaults:savedNumberDict ];
    }

    [window addSubview:viewController.view];
    [window makeKeyAndVisible]; 
}
+1  A: 

Is this piece of code definitely the root of the error? Are you not trying to access savedNumberDict elsewhere? Since it is declared inside your if {} block, it only exists within the if {}, once the code exits that block the variable ceases to exist.

TabbyCool
A: 

Thanks for the response. When I run the Debugger the line that causes the program to crash is: [window makeKeyAndVisible]; When looking at the Debugger with the Breakpoints the point that shows the outofscope error is: self.savedNumber. It is the savedNumber that says it is outofscope. So the suggestion is, is that some where else the savedNumber is outofscope which is affecting this section of code? Jay

JayM