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];
}
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.
精彩评论