• 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: NSDictionary mutability test
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary mutability test


  • Subject: Re: NSDictionary mutability test
  • From: "email@hidden" <email@hidden>
  • Date: Mon, 8 Dec 2008 21:16:58 +0000

Thanks for the lateral insight.
Ran a quick test and it looks as if  the defective

NSAssert([dict isKindOfClass:[NSMutableDictionary class]], @"dict is not mutable");

can be recomposed as

NSAssert([dict classForCoder] == [NSMutableDictionary class], @"dict is not mutable");

The recomposed assert catches the fault condition that the original missed.

Very useful, but given the nature of this I would hesitate to cook up an -isMutable category method.

By the way, putting isKindOfClass: NSMutableDictionary class into google code search implies that everyone is at it.

<email@hidden> wrote:
This is explained in the thread you referenced. All NSDictionary objects are instances of NSCFDictionary. Thus the only way to check if they are mutable through public API is to try mutating them and see if Cocoa throws a hissy fit.

You can use -classForCoder and that will give you either NSDictionary or NSMutableDictionary. This is a public API but the result is not documented to be useful in this manner, so don't use this in any shipping app. (Although given the need for archives to remain backwards compatible I would not expect it to ever change.) However it could be handy for debugging purposes.

Mike

Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




_______________________________________________

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


  • Prev by Date: Re: NSDictionary mutability test
  • Next by Date: Re: building a custom NSView with IB?
  • Previous by thread: Re: NSDictionary mutability test
  • Next by thread: Weird behavior of mouse location when performing a drag
  • Index(es):
    • Date
    • Thread