Re: Determining if NS/CFDictionary is mutable?
Re: Determining if NS/CFDictionary is mutable?
- Subject: Re: Determining if NS/CFDictionary is mutable?
- From: Nicholas Riley <email@hidden>
- Date: Tue, 24 Dec 2002 14:46:25 -0600
- Mail-followup-to: Douglas Davidson <email@hidden>, email@hidden
On Mon, Dec 23, 2002 at 05:26:43PM -0800, Douglas Davidson wrote:
>
When a method states that it returns an NSDictionary rather than an
>
NSMutableDictionary, it's not stating that the dictionary returned is
>
in fact immutable. Rather, it's stating that the dictionary should not
>
be mutated by the caller. Likewise, when a method states that it takes
>
an NSDictionary rather than an NSMutableDictionary, it's stating that
>
it will not mutate the dictionary. You can think of this as being like
>
a "const" keyword.
>
>
If you receive a dictionary, you can't just look at it and decide that
>
it's mutable, therefore it's OK to mutate it. Whoever sent it to you
>
has a right to expect that it will not be mutated, if it was returned
>
via a method returning NSDictionary, or passed in to a method taking
>
NSDictionary.
Thanks, that really clarifies the usage patterns. I really should
have understood that, but I was too caught up in the mechanics of the
serialization mechanism I was implementing.
In my case the object ownership rules are very clear (the invocations
are of a superclass's implementation of the same method, which returns
a dictionary that the subclasses' implementations modify), but it
turns out I can easily change the API so it requires create half as many
autoreleased objects - which is fine for my purposes.
Thanks again to everyone who responded,
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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.