• 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: NSThread/NSMutableArray oddity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSThread/NSMutableArray oddity


  • Subject: Re: NSThread/NSMutableArray oddity
  • From: j o a r <email@hidden>
  • Date: Fri, 12 Apr 2002 07:41:47 +0200

On Friday, April 12, 2002, at 06:31 , Matt Majka wrote:

New problem. Having trouble setting an array of NSColors
as a user default. Any ideas there?

You should not store things in NSUserDefaults that aren't a valid property list object - ie. either: NSData, NSString, NSNumber, NSDate, NSArray or NSDictionary.
Other objects, objects in the object hierarchies rooted in an array or dictionary, or plain data types, needs to be converted into one of these first in order to be accepted by the user defaults system.

In your case that means that you need to convert your array of NSColor into an array of NSData doing something like this (original code from Ali Ozer in the thread "saving NSColors to NSUserDefaults" on this mailing list):

NSData *data = [NSArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:data
forKey:@"MyColor"];

To read it back you would do:

NSData *data = [[NSUserDefaults standardUserDefaults]
objectForKey:@"MyColor"];
NSColor *color = [NSUnarchiver unarchiveObjectWithData:data];


This is not very well documented for NSUserDefaults - just hinted at indirectly, like in the description for the method "persistentDomainForName:". Someone should report this through RadarWeb to have the documentation updated and improved.

j o a r
_______________________________________________
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:
    • Re: NSThread/NSMutableArray oddity
      • From: Matt Majka <email@hidden>
References: 
 >Re: NSThread/NSMutableArray oddity (From: Matt Majka <email@hidden>)

  • Prev by Date: NSTextView --> styled TextEdit, how?
  • Next by Date: Re: Problem linking to zlib
  • Previous by thread: Re: NSThread/NSMutableArray oddity
  • Next by thread: Re: NSThread/NSMutableArray oddity
  • Index(es):
    • Date
    • Thread