views:

63

answers:

2

I need to store the memory address of an Object as an NSString. Is there a special format specifier for that?

+7  A: 

%p should work for any pointer, including pointers to objects. So:

NSString *addr = [NSString stringWithFormat:@"%p", obj];

That will be a string beginning with 0x and in hexadecimal.

John Calsbeek
+1  A: 

Yes, you can use the %p formatter to get the address of an object as a string. Something like this would work:

NSString *pstr = [NSString stringWithFormat:@"%p", myPtr];
mipadi