FROM : Mike Ferris
DATE : Thu Jan 09 19:47:31 2003
When you call -registerDefaults the values go into the "registration"
domain which is not a persistent domain. In NSUserDefaults there's a
stack of domains (which used to be simple and is not actually quite
complicated with the introduction of things like per-host and any-user
defaults when CFPreferences came along...) Domains are either
persistent or not. The canonical examples of non-persistent domains
are the registration domain and the command-line-arguments domain (any
command line argument pair "-<foo> <bar>" will cause the default <foo>
to be set to <bar> in the command-line-argument domain.)
If you want to set defaults that will stick, the usual way is simply to
send -setObject:forKey: to NSUserDefaults. This convenience method
(and the others like it) will put the value into the most common domain
(the this-user, this-app, any-machine domain).
Otherwise you need to use the API for fetching and setting whole domain
dictionaries if you need the value to go into some other domain.
Note that it is often customary not to write out preferences until the
user actually changes them from their default values but this is
something that an app either does or does not do. It is not a feature
of NSUserDefaults. With NSUserDefaults if you put a value in a
persistent domain, it will be written.
Mike
Begin forwarded message:
> From: Pierre-Olivier Latour <<email_removed>>
> Date: Wed Jan 8, 2003 12:51:00 PM US/Pacific
> To: Cocoa Developers <<email_removed>>
> Subject: Forcing NSUserDefaults being written to disk?
>
> Hi,
>
> I have an application that has no UI. Its settings have to be set by
> editing
> its defaults file (.plist). I use the following code to register the
> defaults at startup:
>
> + (void) initialize
> {
> NSMutableDictionary* defaults = [NSMutableDictionary
> dictionary];
>
> [defaults setInt:640 forKey:kKey_ScreenWidth];
> [defaults setInt:480 forKey:kKey_ScreenHeight];
> [defaults setInt:32 forKey:kKey_ScreenDepth];
> [defaults setInt:16 forKey:kKey_ZDepth];
> [defaults setBool:YES forKey:kKey_VerticalSync];
> [defaults setInt:0 forKey:kKey_MaxFPS];
>
> [defaults setBool:YES forKey:kKey_LogFile];
> [defaults setInt:8765 forKey:kKey_ServerPort];
> [defaults setBool:NO forKey:kKey_HighPriorityThread];
>
> [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
> }
>
> My problem is that, even if I call [[NSUserDefaults
> standardUserDefaults]
> synchronize] when application quits (it returns true), no file is
> written in
> ~/Library/Preferences/;
>
> According to the doc, it should be written when you call synchronize,
> even
> if no changes have been made to the defaults...
>
> So I tried changing artificially the defaults before calling
> sycnhronize
> i.e:
> [defaults setBool:![defaults boolForKey:kKey_VerticalSync]
> forKey:kKey_VerticalSync];
> [defaults setBool:![defaults boolForKey:kKey_VerticalSync]
> forKey:kKey_VerticalSync];
>
> Now a file is created but it contains only the key kKey_VerticalSync!
>
> Any idea?
>
> PS: I assume synchronize if buggy.
>
> _____________________________________________________________
>
> Pierre-Olivier Latour <email_removed>
> Palo Alto, USA http://www.pol-online.net
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Thu Jan 09 19:47:31 2003
When you call -registerDefaults the values go into the "registration"
domain which is not a persistent domain. In NSUserDefaults there's a
stack of domains (which used to be simple and is not actually quite
complicated with the introduction of things like per-host and any-user
defaults when CFPreferences came along...) Domains are either
persistent or not. The canonical examples of non-persistent domains
are the registration domain and the command-line-arguments domain (any
command line argument pair "-<foo> <bar>" will cause the default <foo>
to be set to <bar> in the command-line-argument domain.)
If you want to set defaults that will stick, the usual way is simply to
send -setObject:forKey: to NSUserDefaults. This convenience method
(and the others like it) will put the value into the most common domain
(the this-user, this-app, any-machine domain).
Otherwise you need to use the API for fetching and setting whole domain
dictionaries if you need the value to go into some other domain.
Note that it is often customary not to write out preferences until the
user actually changes them from their default values but this is
something that an app either does or does not do. It is not a feature
of NSUserDefaults. With NSUserDefaults if you put a value in a
persistent domain, it will be written.
Mike
Begin forwarded message:
> From: Pierre-Olivier Latour <<email_removed>>
> Date: Wed Jan 8, 2003 12:51:00 PM US/Pacific
> To: Cocoa Developers <<email_removed>>
> Subject: Forcing NSUserDefaults being written to disk?
>
> Hi,
>
> I have an application that has no UI. Its settings have to be set by
> editing
> its defaults file (.plist). I use the following code to register the
> defaults at startup:
>
> + (void) initialize
> {
> NSMutableDictionary* defaults = [NSMutableDictionary
> dictionary];
>
> [defaults setInt:640 forKey:kKey_ScreenWidth];
> [defaults setInt:480 forKey:kKey_ScreenHeight];
> [defaults setInt:32 forKey:kKey_ScreenDepth];
> [defaults setInt:16 forKey:kKey_ZDepth];
> [defaults setBool:YES forKey:kKey_VerticalSync];
> [defaults setInt:0 forKey:kKey_MaxFPS];
>
> [defaults setBool:YES forKey:kKey_LogFile];
> [defaults setInt:8765 forKey:kKey_ServerPort];
> [defaults setBool:NO forKey:kKey_HighPriorityThread];
>
> [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
> }
>
> My problem is that, even if I call [[NSUserDefaults
> standardUserDefaults]
> synchronize] when application quits (it returns true), no file is
> written in
> ~/Library/Preferences/;
>
> According to the doc, it should be written when you call synchronize,
> even
> if no changes have been made to the defaults...
>
> So I tried changing artificially the defaults before calling
> sycnhronize
> i.e:
> [defaults setBool:![defaults boolForKey:kKey_VerticalSync]
> forKey:kKey_VerticalSync];
> [defaults setBool:![defaults boolForKey:kKey_VerticalSync]
> forKey:kKey_VerticalSync];
>
> Now a file is created but it contains only the key kKey_VerticalSync!
>
> Any idea?
>
> PS: I assume synchronize if buggy.
>
> _____________________________________________________________
>
> Pierre-Olivier Latour <email_removed>
> Palo Alto, USA http://www.pol-online.net
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Pierre-Olivier Lat… | Jan 8, 21:51 | |
| Robert Cerny | Jan 9, 09:12 | |
| Scott Anguish | Jan 9, 10:18 | |
| Pierre-Olivier Lat… | Jan 9, 11:04 | |
| Marco Binder | Jan 9, 15:44 | |
| Alex Rice | Jan 9, 16:18 | |
| Mike Ferris | Jan 9, 19:47 | |
| Pierre-Olivier Lat… | Jan 9, 20:24 | |
| Pierre-Olivier Lat… | Jan 9, 20:25 | |
| Chris Parker | Jan 9, 22:34 |






Cocoa mail archive

