iOS — get pointer from NSString containing address

后端 未结 5 481
名媛妹妹
名媛妹妹 2021-01-01 02:57

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 stringWithForm         


        
5条回答
  •  囚心锁ツ
    2021-01-01 03:46

    Use an NSMapTable instead:

    MyClass* p = [[MyClass alloc]init];
    NSMapTable* map = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableStrongMemory];
    [map setObject:whateverValue forKey:p];
    // ...
    for(MyClass* key in map) {
    // ...
    }
    

提交回复
热议问题