On Jul 28, 2008, at 3:24 PM, David Wilson wrote:
On Mon, Jul 28, 2008 at 2:13 PM, Carter R. Harrison
<[EMAIL PROTECTED]> wrote:
Hey Everybody,
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?
Right now I'm doing this:
int i;
for (i = 0 ; i < 10 ; i++)
{
NSObject *myObject = [[NSObject alloc] init];
[dictionary setValue:myObject forKey:[NSString
stringWithFormat:@"%x",
&myObject]];
}
Use:
int i;
for (i=0;i<10;i++)
{
NSObject *myObject = [[NSObject alloc] init];
NSValue *val = [NSValue valueWithPointer:myObject];
[dictionary setValue:myObject forKey:val];
}
Or [NSNumber numberWithInt:(int)myObject] instead of the NSValue.
Actually now that I'm looking at this more closely, NSDictionary is
expecting an NSString for the key when inserting a value. Your
example uses an NSValue for the key - the compiler is throwing a
warning for this one..
--
- David T. Wilson
[EMAIL PROTECTED]
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]