Re: Crash while making NSDictionary... Help!
Re: Crash while making NSDictionary... Help!
- Subject: Re: Crash while making NSDictionary... Help!
- From: Andy Lee <email@hidden>
- Date: Tue, 21 May 2002 23:21:52 -0400
At 7:51 PM -0700 5/21/02, Dylan Barrie wrote:
NSUserDefaults *defaults;
NSDictionary *appDefaults;
NSString *keys[2];
NSString *values[2];
keys[0] = @"Name";
values[0] = @"Unnamed Player";
keys[1] = @"FirstRun";
values[1] = @"YES";
NSLog (@"1) %@ %@ 2) %@ %@", keys[0], values[0], keys[1], values[1]);
appDefaults = [NSDictionary dictionaryWithObjects:(id *)values
forKeys:(id *)keys count:2];
[defaults registerDefaults:appDefaults];
It crashes trying to create the NSDictionary (appDefaults =
[NSDictionary ... ]), and I'm not sure why.
The problem is here:
[defaults registerDefaults:appDefaults];
The variable "defaults" has not been initialized to anything, and
therefore contains an unpredictable value. You are sending the
-registerDefaults: message to a non-nil non-object, hence the crash.
I haven't used NSUserDefaults myself, but it looks like you should try...
defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:appDefaults];
...or simply:
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
I know you thought the problem was in creating the NSDictionary, but
it doesn't look that way.
--Andy
P.S. Hey look guys, this time I *am* making the right call about an
uninitialized variable. ;)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.