Re: Defaults not stored
Re: Defaults not stored
- Subject: Re: Defaults not stored
- From: Mike Abdullah <email@hidden>
- Date: Thu, 04 Apr 2013 10:32:53 +0100
On 4 Apr 2013, at 09:18, Stephane Sudre <email@hidden> wrote:
> On Thu, Apr 4, 2013 at 5:56 AM, Steve Mills <email@hidden> wrote:
>> My screensaver follows examples I've seen as far as creating its defaults in its initWithFrame method:
>>
>> ScreenSaverDefaults* defaults = [ScreenSaverDefaults defaultsForModuleWithName:MyModuleName];
>>
>> // Register our default values:
>> fileMan = [[NSFileManager alloc] init];
>>
>> NSURL* defaultURL = [NSURL URLWithString:@"/Applications"];
>> NSArray* pictFolders = [fileMan URLsForDirectory:NSPicturesDirectory inDomains:NSUserDomainMask];
>>
>> if(pictFolders != nil && [pictFolders count] > 0)
>> defaultURL = [[pictFolders objectAtIndex:0] filePathURL];
>>
>> [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
>> defaultURL, kImageFolderPathPrefKey,
>> [NSNumber numberWithInteger:NSOnState], kUsePolaroidBorderPrefKey,
>> nil]];
>>
>> Then later in my startAnimation method I grab that value, but it's nil:
>>
>> ScreenSaverDefaults* defaults = [ScreenSaverDefaults defaultsForModuleWithName:MyModuleName];
>> NSURL* url = [defaults URLForKey:kImageFolderPathPrefKey];
>>
>> I tried calling [defaults synchronize] after registerDefaults, but that didn't help. I also tried creating a mutable dictionary and adding the url and integer via setObject:forKey:. No matter which method I use to create the defaults, I can definitely *see* the url in the defaults object, but it comes out nil when I ask for URLForKey. If I actually go through the System Preferences window and set my screen saver's prefs from there, then the url comes out as a valid value.
>>
>> What am I doing wrong?
>
> AFAIK, you can't save a NSURL instance in the defaults/preferences of
> an application using a NSDictionary or NSArray that contain a NSURL
> object. You have to use the setURL: forKey: for it work.
>
> Personally, I've given up thinking about using NSURL in defaults for a
> screen saver and just use a NSString with the absolute path.
Storing bookmark data is preferable. It allows the app to cope with the item at that URL being moved. Additionally, the bookmark can be security-scoped, which is very useful to sandboxed apps
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden