• 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
Crash while making NSDictionary... Help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Crash while making NSDictionary... Help!


  • Subject: Crash while making NSDictionary... Help!
  • From: Dylan Barrie <email@hidden>
  • Date: Tue, 21 May 2002 19:51:11 -0700

I'm trying to create an NSDictionary to use as my default preferences (for my NSUserDefaults), and I'm having a little trouble.

This is the exact code that I am using:

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.

I was looking at a tutorial, and it had this code:
static const int N_ENTRIES = 26;
NSDictionary *asciiDict;
NSString *keyArray[N_ENTRIES];
NSNumber *valueArray[N_ENTRIES];
int i;

for (i = 0; i < N_ENTRIES; i++) {
char charValue = 'a' + i;
keyArray[i] = [NSString stringWithFormat:@"%c", charValue];
valueArray[i] = [NSNumber numberWithChar:charValue];
}

asciiDict = [NSDictionary dictionaryWithObjects:(id *)valueArray
forKeys:(id *)keyArray count:N_ENTRIES];

And this code did NOT crash. I'm not seeing how mine is any different.

If it matters, PB says that my app is crashing due to a signal 11 (SIGSEGV).

Thanks in advance,

Dylan Barrie
_______________________________________________
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: Andy Lee <email@hidden>
  • Prev by Date: Re: Ints in NSDictionaries
  • Next by Date: How to update LaunchServices database?
  • Previous by thread: Re: Build Log
  • Next by thread: Re: Crash while making NSDictionary... Help!
  • Index(es):
    • Date
    • Thread