Re: UserDefaults (Java)
Re: UserDefaults (Java)
- Subject: Re: UserDefaults (Java)
- From: Chris Parker <email@hidden>
- Date: Thu, 27 Dec 2001 20:12:49 -0500
Hi Simon,
On Wednesday, December 26, 2001, at 07:11 PM, Simon Wright wrote:
registerDefaults is expecting an NSDictionary so I'm doing this...
NSMutableDictionary appDefaults = new NSMutableDictionary();
appDefaults.setObjectForKey(defaultAutoStart, "autoStart");
appDefaults.setObjectForKey(defaultCycleDelay, "cycleDelay");
myDefaults.registerDefaults(appDefaults);
The variables defaultAutoStart and defaultCycleDelay are a boolean and
an integer respectively but the compiler barfs on the setObjectForKey
lines with the message...
DataTable.java:71: setObjectForKey(java.lang.Object,java.lang.Object)
in com.apple.cocoa.foundation.NSMutableDictionary cannot be applied to
(boolean,java.lang.String) [or int version]
What you'll have to do is create a java.lang.Number for
defaultCycleDelay, like so:
Integer defaultCycleDelayAsInteger = new Integer(defaultCycleDelay);
and then add that to your mutable dictionary.
I'm sure I'm missing something simple. When I update the UserDefaults
from my Preferences window I can use the method...
myDefaults.setIntegerForKey(cycleDelay, "cycleDelay");
and...
myDefaults.setBooleanForKey(autoStart, "autoStart");
Here, setBooleanForKey and setIntegerForKey are convenience methods that
construct appropriate objects and put these into the user defaults
database.
Hope this helps you out,
.chris
--
Chris Parker
Cocoa Frameworks Engineer
Apple Computer, Inc.