Re: NSDictionary question
Re: NSDictionary question
- Subject: Re: NSDictionary question
- From: Ondra Cada <email@hidden>
- Date: Fri, 15 Nov 2002 01:11:34 +0100
On Thursday, November 14, 2002, at 07:58 , Hisaoki Nishida wrote:
It says that value objects are retained while key objects are copied.
How do I know if the object I am adding is a value or a key object?
Oops. It's not what the argument is, but how it is used: key is a key,
value is the appropriate object.
Keys are those objects in the key array, values those in the value array.
If you used dictionaryWithObjectsAndKeys, then keys are odd ones and
values even ones. And if you added to (mutable) dictionary with
setValue:forKey:, then object is always the former, whilst key the latter
argument.
I know NSNumber for example is a value object, but what makes it
different from an object I create that wraps a number. It's still
conceptually a short-lived value object. How does it know it is a value
object?
Since you used it that way.
Also, in a related matter, just to be sure I want to ask if
objectForKey: instance method returns a copy or a reference.
With general classes you don't know and don't need to know. Containers
(array, dictionary, set) though are considered low-level enough not to do
anything behind the scenes (but what is cleanly documented for them), so,
in this case, you always get a reference.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.