Re: NSUserDefault at first startup
Re: NSUserDefault at first startup
- Subject: Re: NSUserDefault at first startup
- From: Alex Lock <email@hidden>
- Date: Sat, 4 Oct 2003 16:44:08 -0400
On Saturday, October 4, 2003, at 03:18 PM, David Dauer wrote:
Hello all
I have a NSMutableArray *array; and assign this array a dictionary.
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
array = [[defaults objectForKey:@"key"] retain];
But when the user start my app the first time, the array is (NULL) and
it's
not possible to set any dict or object to the array.
How to fix that?
Thanks
David
Try something like this:
if (array == nil) {
NSMutableArray *myArray = [[NSMutableArray alloc] initWithSize:1];
[myArray addObject:myObject];
[defaults setObject:myArray forKey:@"key"];
[myArray release];
}
If you need to add more than one object, obviously, you would put the
addObject message inside a loop of some kind.
Hope that helps!
Alex <email@hidden>
_______________________________________________
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.