Crash while making NSDictionary... Help!
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.