[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: User preferences
From: |
Richard Frith-Macdonald |
Subject: |
Re: User preferences |
Date: |
Thu, 16 Dec 2004 06:03:37 +0000 |
On 15 Dec 2004, at 23:50, Samuel Hornus wrote:
Hi !
Being happy with my little GUI, I would like to store/retreive some
user
preferences. NSUserDefaults seems the way to go, and after reading some
(but certainly not the most relevant :-( ) documentation, I followed
the
advices from this web page:
http://developer.apple.com/documentation/Cocoa/Conceptual/
UserDefaults/Tasks/UsingDefaults.html#//apple_ref/doc/uid/20000719
Looks fine ... nothing there which should not work in GNUstep.
Needless to say, it does not work. I kinda feel that I may need to
supply some "default domain name" to the NSUserDefaults, but I can't
see
where/what/when/why/...
No, you don't need to supply a domain name.
Do you have some clues about saving some prefs and retrieving them ?
What need be added to the code examplified in the webpage above ?
Thank you in advance !
To save -
// Set a default string in the default domain for the application
[[NSUserDefaults standardUserDefaults] setObject: @"aValue" forKey:
@"aKey"];
// Retrieve the value from the defaults system
value = [[NSUserDefaults standardUserDefaults] objectForKey: @"aKey"];
/*
* NB. when a default value is set, it is cached in memory and not
written to disk until
* later on when the run loop is running and a regular housekeeping
timer goes off.
* If your program exits shortly after setting a default, or if your
program is not using
* a run loop, you need to explicitly flush the cached default data to
disk by calling
* the synchronize method. The apple documentation does talk about
this, but perhaps
* not as clearly as it should.
*/
[[NSUserDefaults standardUserDefaults] synchronize];