If I have a pointer to a foo object with the address (say) 0x809b5c0, I can turn this into an NSString by calling
NSString* fooString = [NSString stringWithFormat: @"%p", foo].
This will give me NSString @ "0x809b5c0".
What is the easiest way to reverse the process? That is, start with fooString and return my pointer to foo.
Convert it to an integer, and then apply it to any type that should be ...
NSUInteger myInt = [ myStr integerValue ]; char * ptr = ( char * )myInt;
However, I really don't understand why you need this ...
In its entirety ...
To address bar
NSString *foo = @"foo"; NSString *address = [NSString stringWithFormat:@"%p", foo];
And back
NSString *fooAgain; sscanf([address cStringUsingEncoding:NSUTF8StringEncoding], "%p", &fooAgain);
:
NSString *pointerString = @"0x809b5c0"; NSObject *object; sscanf([pointerString cStringUsingEncoding:NSUTF8StringEncoding], "%p", &object);
NSInteger, :
MyObject *object=[[MyObject alloc]init]; //... NSInteger adress=(NSInteger)object;
MyObject *otherObject=(MyObject*)adress;
: object == otherObject
Use NSMapTable instead:
MyClass* p = [[MyClass alloc]init]; NSMapTable* map = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableStrongMemory]; [map setObject:whateverValue forKey:p]; // ... for(MyClass* key in map) { // ... }