• 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 17:38:08 +0000

Thanks for the reply.

I am aware of why the assertion is never applied but the thread I referenced was several years old and I was hoping that there had been some progress on this.
Maybe not.
I was using this assertion (written some time ago in ignorance) and wasted an afternoon tracking down the fact that it didn't work.
Maybe the only solution is to set up an exception handler.


On 8 Dec 2008, at 17:31, Jonathan Hendry wrote:

It's because NSMutableDictionary is part of a class cluster:

From the NSObject protocol docs:

Be careful when using this method on objects represented by a class cluster. Because of the nature of class clusters, the object you get back may not always be the type you expected. If you call a method that returns a class cluster, the exact type returned by the method is the best indicator of what you can do with that object. For example, if a method returns a pointer to an NSArray object, you should not use this method to see if the array is mutable, as shown in the following code:

// DO NOT DO THIS!
if ([myArray isKindOfClass:[NSMutableArray class]])
{
// Modify the object
}

On Dec 8, 2008, at 12:15 PM, email@hidden wrote:

There are a number of posts detailing with the ethics of the issue of determining an object's mutability.
eg: http://www.cocoabuilder.com/archive/message/cocoa/2004/7/7/111173
Does anyone have a current informed pragmatic opinion on how to deal with the following example?


I am not trying to determine program flow by determining mutability, merely trying to limit the number of self inflicted injuries.
The following never seems to assert, regardless of whether dict is mutable or not.


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

I know that it is my responsibility to remain aware of an object's allocated class but sometimes I find myself wanting.

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

Jonathan Hendry

Howard Hughes Medical Institute
Maunsell Lab
Harvard Medical School



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


  • Follow-Ups:
    • Re: NSDictionary mutability test
      • From: Sherm Pendley <email@hidden>
    • Re: NSDictionary mutability test
      • From: Devon Ferns <email@hidden>
References: 
 >NSDictionary mutability test (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: NSDictionary mutability test
  • Next by Date: Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
  • Previous by thread: Re: NSDictionary mutability test
  • Next by thread: Re: NSDictionary mutability test
  • Index(es):
    • Date
    • Thread