如何在代码中的某个位置捕获对象的地址? 例如:
NSString * aString = @"bla bla";
//what is the current address of aString. i.e to which address in memory does it currently point to
aString = @"la la la";
//what is the current address of aString.
答案 0 :(得分:6)
示例:
NSString *temp = @"123";
uintptr_t ptrAddress = (uintptr_t) temp;
NSLog(@"%@ %p %lu", temp, temp, ptrAddress);
控制台:
2013-07-11 11:51:20.796 asd [6474:907] 123 0x17985c 1546332
它可能对您有用 - NSPointerArray(iOS 6 +)
答案 1 :(得分:4)
这很简单,只需这样做:
NSLog(@"%p", aString);
这是打印指针的格式规范。