• 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: Storing values in dictionary with their address as the key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Storing values in dictionary with their address as the key


  • Subject: Re: Storing values in dictionary with their address as the key
  • From: Manfred Schwind <email@hidden>
  • Date: Tue, 29 Jul 2008 15:26:00 +0200

If I wanted to store an object in a dictionary and set its key as the object's memory address - how would I go about doing this?

NSObject *myObject = [[NSObject alloc] init];
[dictionary setValue:myObject forKey:[NSString stringWithFormat:@"%x", &myObject]];


Just remove the "&" before myObject in your code. You stored the address of the myObject variable (that's on the stack) as key into the dictionary instead of the address of the objects it points to.

But: This does not make any sense to me. A dictionary is used to store objects with a key and retrieve them later with that key. But if the key is the address of the object, you don't need a dictionary at all, because if you already know the address (your "key") you can just use that address to "retrieve" the object. So there is no reason to look that up in a dictionary. E.g. if you look up the object for key "123456" you get back a pointer to 123456. That's information you already have in your hands and you don't need the dictionary at all.

I would really like to know a meaningful situation for such a scenario. Maybe I just can not think of one. Or maybe you just simplified your problem. I don't know.

Regards,
Manfred Schwind
--
http://mani.de - friendly software
iVolume - listen to music freehand
LittleSecrets - the encrypted notepad

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


References: 
 >Storing values in dictionary with their address as the key (From: "Carter R. Harrison" <email@hidden>)

  • Prev by Date: Re: sorting two arrays
  • Next by Date: Re: [Newbie] Communication between two Views?
  • Previous by thread: Re: Storing values in dictionary with their address as the key
  • Next by thread: Shameless Ottawa (Canada) Cocoaheads plug
  • Index(es):
    • Date
    • Thread