• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Crash while making NSDictionary... Help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: Crash while making NSDictionary... Help!
      • From: Scott Anguish <email@hidden>
    • Re: Crash while making NSDictionary... Help!
      • From: Dylan Barrie <email@hidden>
References: 
 >Crash while making NSDictionary... Help! (From: Dylan Barrie <email@hidden>)

  • Prev by Date: Setting __MyCompanyName__
  • Next by Date: Re: Setting __MyCompanyName__
  • Previous by thread: Crash while making NSDictionary... Help!
  • Next by thread: Re: Crash while making NSDictionary... Help!
  • Index(es):
    • Date
    • Thread