开发者

Why is there no * in this method declaration?

Here is the method declaration midway in Apple's documentation: Learning Objective-C: A Primer

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

Why is there no * right after NSUInteger. I thought all objects were pointer types and all strongly typed pointers had to have 开发者_开发问答a * character after it.


NSUInteger is not an object type, it is a typedef to unsigned int.

The only reason that you would actually want to use a * in this context would be if you wanted to get the address of an int and store something in it. (Some libraries do this with error messaging). An example of this:

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

NSUInteger a;
[obj methodName: &a]; //a is now 5
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜