• 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
NSUserDefaults Croaks on Dictionary Containing NSNumber as Key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSUserDefaults Croaks on Dictionary Containing NSNumber as Key


  • Subject: NSUserDefaults Croaks on Dictionary Containing NSNumber as Key
  • From: Jerry Krinock <email@hidden>
  • Date: Fri, 11 Dec 2009 23:10:59 -0800

Sorry for the wonky subject.  It's easier to explain in code:

NSNumber* innerKey = [NSNumber numberWithInt:0] ;
NSDictionary* dic = [NSDictionary dictionaryWithObject:@"Hello"
                                                forKey:innerKey] ;
[[NSUserDefaults standardUserDefaults] setObject:dic
		                          forKey:@"outerKey"] ;

Result:

*** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '{
    0 = Hello;
}' of class 'NSCFDictionary'.

If I change innerKey to a string such as @"0", then all works fine.

In my opinion, after reading the documentation carefully, this exception is a false alarm.  First of all, NSCFDictionary *is*, as required, one of the "property list" objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.  Furthermore, all of its objects and keys are themselves property list objects.  Furthermore, NSNumber conforms to NSCopying protocol, as required for dictionary keys.

Is there some other requirement that I missed?

Jerry Krinock

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSUserDefaults Croaks on Dictionary Containing NSNumber as Key
      • From: Chris Parker <email@hidden>
    • Re: NSUserDefaults Croaks on Dictionary Containing NSNumber as Key
      • From: Clark Cox <email@hidden>
  • Prev by Date: Re: Hang Initializing App
  • Next by Date: Re: NSUserDefaults Croaks on Dictionary Containing NSNumber as Key
  • Previous by thread: -[NSWorkspace absolutePathForAppBundleWithIdentifier:] and the Trash
  • Next by thread: Re: NSUserDefaults Croaks on Dictionary Containing NSNumber as Key
  • Index(es):
    • Date
    • Thread