• 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: Mutable class problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mutable class problems


  • Subject: Re: Mutable class problems
  • From: Andy Lee <email@hidden>
  • Date: Tue, 25 Jun 2002 05:06:22 -0400

At 10:36 PM -0600 6/24/02, Mike Shields wrote:
I seem to remember a conversation where checking for immutablity was bound to fail in some obscure way.

Because of the class-cluster-ness, there's no guarantee what actual class will be returned when you instantiate NSDictionary. And in fact, it looks like you get the same class whether you instantiate NSDictionary or NSMutableDictionary (at least as they're implemented today). So neither -respondsToSelector: nor even -isKindOfClass: is a reliable test for immutability.

But strictly speaking, if all you cared about was the right answer to the immutability question, it seems to me you could try actually sending a mutating message:

BOOL isImmutable = NO;

NS_DURING
[[myDictionary copy] setObject:@"foo" forKey:@"bar"];
NS_HANDLER
isImmutable = YES;
NS_ENDHANDLER

NSLog(@"isImmutable? %d", isImmutable);

Of course, this is pretty ugly and wasteful and unnecessary for Rosyna's purposes. But technically, it should work for all but a few cases where, for example, you define your own subclass of NSDictionary and do something weird.

--Andy
_______________________________________________
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: Mutable class problems
      • From: Rosyna <email@hidden>
References: 
 >Re: Mutable class problems (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Mutable class problems
  • Next by Date: Code design question
  • Previous by thread: Re: Mutable class problems
  • Next by thread: Re: Mutable class problems
  • Index(es):
    • Date
    • Thread