If I have a pointer to an object foo with address (say) 0x809b5c0, I can turn that into an NSString by calling
NSString* fooString = [NSString stringWithFormat: @"%p", foo].
This will give me the NSString @"0x809b5c0".
What is the easiest way to reverse the process? That is, start with fooString, and get back my pointer to foo.
In its completeness...
To address-string
NSString *foo = @"foo";
NSString *address = [NSString stringWithFormat:@"%p", foo];
And back
NSString *fooAgain;
sscanf([address cStringUsingEncoding:NSUTF8StringEncoding], "%p", &fooAgain);
This snippet worked for me:
NSString *pointerString = @"0x809b5c0";
NSObject *object;
sscanf([pointerString cStringUsingEncoding:NSUTF8StringEncoding], "%p", &object);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With