• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: NSDictionary question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: NSDictionary question


  • Subject: RE: NSDictionary question
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Fri, 15 Nov 2002 14:41:04 -0500

> 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?
> 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?

You are reading way too much into the phrase "value object" in the docs.
Any object, regardless of class, can be a member of an NSDictionary. The
object does not have to belong to a "value" class, whatever that means. The
docs simply attempt to draw a distinction between an object in an
NSDictionary and its key. An entry in a dictionary is called a "key-value
pair." I bet that's why they call the one that isn't the key a "value
object."

Like the other collections, dictionaries retain objects that are added to
them and release objects that are removed from them. In a dictionary, a key
is treated a little differently. It isn't retained; it's copied with
copyWithZone:. As a result, the key object must conform to the NSCopying
protocol. That all the doc is trying to say.


>
> Also, in a related matter, just to be sure I want to ask if
> objectForKey: instance method returns a copy or a reference.

It returns a reference -- an id, really. You may have to retain it.

Jonathan
_______________________________________________
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.

References: 
 >NSDictionary question (From: Hisaoki Nishida <email@hidden>)

  • Prev by Date: RE: Beginner questions
  • Next by Date: Re: NSOutlineView selection questions
  • Previous by thread: Re: NSDictionary question
  • Next by thread: Re: NSDictionary question
  • Index(es):
    • Date
    • Thread