Re: NSUserDefaults and NSArray
Re: NSUserDefaults and NSArray
- Subject: Re: NSUserDefaults and NSArray
- From: jerome LAURENS <email@hidden>
- Date: Mon, 16 Sep 2002 13:12:20 +0200
Le vendredi 13 septembre 2002, ` 03:47 PM, j o a r a icrit :
>
Have you verified that you actually find anything in user defaults?
>
Something like this:
>
>
- (void) readMyArray
>
{
>
NSArray * myArray = [[NSUserDefaults standardUserDefaults]
>
objectForKey: @"MyArray"];
>
>
if (myArray != nil) {
>
NSLog(@"Found %d entries in user defaults", [myArray count]);
>
} else {
>
NSLog(@"Nothing stored in user defaults");
>
}
>
}
>
>
this is exactly the kind of problems registerDefaults is made for
Before asking the user defaults for some info, you should register basic
values that make your code consistent
in some +(void)initialize method, put something like
[[NSUserDefaults standardUserDefaults] registerDefaults:
[NSDictionary dictionaryWithObject: [your basic array] forKey:
@"MyArray"]];
then when asking
myArray = [[NSUserDefaults standardUserDefaults] objectForKey:
@"MyArray"]
If there is no object for key @"MyArray" in the user database, [your
basic array] will be returnd instead.
_______________________________________________
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.