Re: Mutable class problems
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.