• 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: Saving preferences tutorial
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving preferences tutorial


  • Subject: Re: Saving preferences tutorial
  • From: Chris Parker <email@hidden>
  • Date: Mon, 30 Jun 2003 18:41:58 -0700

On Monday, June 30, 2003, at 6:25 PM, Jeff Harrell wrote:

I don't know of a tutorial, but it's really as simple as:

[[NSUserDefaults standardUserDefaults] setObject:@"someValue" forKey:@"someKey"];

You can do it with any object, such as a string as shown here, an NSColor, an NSArray, an NSDict, whatever. You can also use setBool:, setFloat:, or setInteger: instead if you want to store one of those values.

Careful... :)

-setObject:forKey: on NSUserDefaults only works for "plist" types, as Dave Thorup indicated in his message earlier in this thread. To quote:

The object types that you can save with NSUserDefaults are as follows:
NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary

If you're going to store anything else in preferences, you'll have to massage them into one of these types.

For NSColors, the best way to do this (keeping fidelity) is to use NSArchiver to change the NSColor into an NSData and then store that. When you read the value from NSUserDefaults, unarchive it back into an NSColor. Sample code for this is likely available in the mailing list archives.

.chris

--
Chris Parker
Cocoa Frameworks
Apple Computer, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Strong language about Cocoa and Qt.
      • From: publiclook <email@hidden>
    • Re: Saving preferences tutorial
      • From: Jeff Harrell <email@hidden>
References: 
 >Re: Saving preferences tutorial (From: Jeff Harrell <email@hidden>)

  • Prev by Date: Re: Saving preferences tutorial
  • Next by Date: Re: Saving preferences tutorial
  • Previous by thread: Re: Saving preferences tutorial
  • Next by thread: Re: Saving preferences tutorial
  • Index(es):
    • Date
    • Thread