Re: UserDefaults (Java)
Re: UserDefaults (Java)
- Subject: Re: UserDefaults (Java)
- From: Chris Parker <email@hidden>
- Date: Thu, 27 Dec 2001 20:17:17 -0500
Nick,
On Thursday, December 27, 2001, at 06:53 AM, Nick M|ller wrote:
On 26.12.2001 at 19:11 Uhr, Simon Wright wrote:
So, I think my question is: how can I get an integer and a boolean
into my NSMutableDictionary?
Why do you put a Dictionary into user defaults? UserDefaults _is_ a
dictionary.
He's registering backstop defaults for the cases where the user hasn't
specified a value, but he wishes to provide a sane fallback value.
registerDefaults() takes a dictionary as its argument. There are a
number of ways to construct your dictionary for this - "by hand" in
code, or by reading a plist in from your application bundle. If you're
going to do it by hand, you need to create the objects that are
appropriate for the types you're putting in (i.e. java.lang.Integer for
an int or java.lang.Float for a floating point number, etc.).
Out of my head (I quit Java for Cocoa due to some missing API)
NSUserDefaults myDefaults = NSUserDefaults.standardUserDefaults();
myDefaults.setIntegerForKey(1, "intKey");
and
int i = myDefaults.integerForKey("intKey");
This means, that you do not have to put an NSDictionary into the
defaults but simply use the wrappers to put types like boolean and int
into a dictionary (that dictionary beeing NSUserDefaults).
This is absolutely correct - and as I mentioned in my reply to Simon,
NSUserDefaults is providing those convenience functions for you -
they're just not available for NSMutableDictionary.
.chris
--
Chris Parker
Cocoa Frameworks Engineer
Apple Computer, Inc.