Re: No sure way to tell whether an array is mutable?
Re: No sure way to tell whether an array is mutable?
- Subject: Re: No sure way to tell whether an array is mutable?
- From: "R. Matthew Emerson" <email@hidden>
- Date: Thu, 25 Jan 2007 21:37:06 -0500
On Jan 25, 2007, at 9:21 PM, Kenny Leung wrote:
I think I have just been burned by something sinister: an object
says that it is an NSMutableArray, but turns out to be non-mutable.
I'm wondering if anyone has run into this:
code snippet:
if ( [newChildren isKindOfClass:[NSMutableArray class]] ) {
HXDebug(@"Mutable:%@", newChildren);
}
[newChildren insertObject:entry atIndex:newIndex];
output:
DEBUG Mutable:()
*** -[NSCFArray insertObject:atIndex:]: mutating method sent to
immutable object
It turns out that the documentation for isKindOfClass: warns about
this very situation.
See <http://developer.apple.com/documentation/Cocoa/Reference/
Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//
apple_ref/occ/intfm/NSObject/isKindOfClass:>
Instead, you might be able to use something like
if ([newChildren respondsToSelector:@selector
(insertObject:atIndex:)]) { ... }
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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