• 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: Defaults not stored
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defaults not stored


  • Subject: Re: Defaults not stored
  • From: Stephane Sudre <email@hidden>
  • Date: Thu, 04 Apr 2013 10:18:03 +0200

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.

_______________________________________________

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

  • Follow-Ups:
    • Re: Defaults not stored
      • From: Mike Abdullah <email@hidden>
References: 
 >Defaults not stored (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Drawing an overbar on text?
  • Next by Date: Re: Defaults not stored
  • Previous by thread: Defaults not stored
  • Next by thread: Re: Defaults not stored
  • Index(es):
    • Date
    • Thread