• 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: Scott Anguish <email@hidden>
  • Date: Wed, 22 May 2002 02:58:59 -0400

Ugh... that seems odd..

I'd suggest not using the C array version whereever possible..


appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:@"Unnamed Player",@"Name",@"YES",@"First Run",nil];
[defaults registerDefaults:appDefaults];


(actually.. what I'd really suggest is pulling the 'default defaults' out of a plist stored in the application wrapper.. its easy to edit without changing code to add new defaults)


appDefaults=[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myDefaults" ofType:@"xml"]];
[defaults registerDefaults:appDefaults];


this will read the XML file with a dictionary of your defaults from a file called myDefaults.xml in the app wrapper...

On Tuesday, May 21, 2002, at 10:51 PM, Dylan Barrie wrote:

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.
_______________________________________________
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.

References: 
 >Crash while making NSDictionary... Help! (From: Dylan Barrie <email@hidden>)

  • Prev by Date: Disabling anti-aliasing in an NSTextView - is it possible?
  • Next by Date: Re: Crash while making NSDictionary... Help!
  • Previous by thread: Re: Crash while making NSDictionary... Help!
  • Next by thread: How to update LaunchServices database?
  • Index(es):
    • Date
    • Thread