• 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: UserDefaults (Java)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >UserDefaults (Java) (From: Simon Wright <email@hidden>)

  • Prev by Date: Re: Newbie Controls Question
  • Next by Date: Re: UserDefaults (Java)
  • Previous by thread: UserDefaults (Java)
  • Next by thread: Re: UserDefaults (Java)
  • Index(es):
    • Date
    • Thread