On Thu, Apr 4, 2013 at 5:56 AM, Steve Mills <[email protected]> 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.

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to