iphone - 如何获取指向 id 变量和 NSObject 指针的指针?

标签 iphone objective-c cocoa macos

id        idPointer = [[SomeObject alloc] init];
NSObject *nsPointer = [[SomeObject alloc] init];

如何获取idPointernsPointer的指针?

最佳答案

要获取指向指针的指针,只需要在变量上添加一个额外的 * 即可。为了分配它们,您通常会获得普通指针&的地址。然后再次取消引用它们,并在前面加上 *

//Declare and Assign them
id       *idPointerPointer = &idPointer;
NSObject **nsPointerPointer = &nsPointer;

//Dereference them (just an example to send a message)
[*idPointerPointer release];
[*nsPointerPointer release];

关于iphone - 如何获取指向 id 变量和 NSObject 指针的指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6776717/

相关文章:

cocoa - 如何在 NSImageView 中设置内容切换动画?

ios - 核心数据 sqlite-wal 文件在插入 ~5000 行时变得巨大(>7GB)

objective-c - 如何使完成按钮在模式表中处于事件状态?

ios - stringWithFormat 生成带有乱码字符的字符串

objective-c - 使用 NSNotification 中断循环

objective-c - 无法将 NSSound 实例放入 NSMutableArray ion cocoa 中

iphone - 在 iPhone 上绘图

iphone - COCOS2D : ScrollView inside a CCScene blocks animation

iPhone - 扩展 UIImage 以在运行时自定义绘图

objective-c - 在 UITextView 中长按获取单词