Re: immutable NSMutableDictionary
Re: immutable NSMutableDictionary
- Subject: Re: immutable NSMutableDictionary
- From: Shawn Erickson <email@hidden>
- Date: Mon, 17 Feb 2003 08:33:57 -0800
On Monday, February 17, 2003, at 04:39 AM, Jirtme Laurens wrote:
In a rather normal piece of code, I came to a weird thing. Assuming
myObject and myString are valid objects,
if([myDictionary isKindOfClass: [NSMutableDictionary class]])
{
[myDictionary setObject: myObject forKey: myKey];
}
when executing this code, I get an exception complaining that
myDictionary is immutable.
How can it be possible?
Sorry still to early for me to think about this... ;-)
I mean by normal piece of code a program where I do not poseAsClass,
forwardInvocation, nor implement any of those "dangerous" runtime
methods.
Its better to query if the target object supports "setObject" or catch
the exception then attempting to verify class.
for example...
if ([myDictionary respondsTo:@selector(setObject:forKey:)])
{
[myDictionary setObject: myObject forKey: myKey];
}
-Shawn
_______________________________________________
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.