为什么这个方法声明中没有*?

时间:2010-06-11 18:20:04

标签: iphone objective-c pointers ios

以下是Apple文档中途的方法声明: Learning Objective-C: A Primer

- (void)insertObject:(id) anObject atIndex:(NSUInteger) index

为什么*之后没有NSUInteger。我认为所有对象都是指针类型,并且所有强类型指针都必须在其后面加上*字符。

1 个答案:

答案 0 :(得分:11)

NSUInteger不是对象类型,而是typedefunsigned int

在这种情况下,您实际想要使用*的唯一原因是,如果您想获取int的地址并在其中存储内容。 (有些库通过错误消息执行此操作)。一个例子:

-(void) methodName: (NSUInteger *) anInt {
    *anInt = 5;
}

NSUInteger a;
[obj methodName: &a]; //a is now 5
相关问题