开发者

Why do we have to put an asterisk on method parameter types in Objective-C?

I'm starting out Objec开发者_如何学Gotive-C and I was wondering, why do we have to put asterisks in the method parameter type?

e.g.

- (void)myMethodThatTakesAString:(NSString*)string;

Thanks in advance!


The asterisk means that the parameter is a pointer to an NSString. You can't pass an NSString to a method, but rather you pass a pointer to it.

Although you might get away with simply using pointers when you have objects and not really understanding them, it's probably a good idea to prioritize learning about pointers.


Because that is what you are passing- a pointer - a memory location or reference to NSString.

The notation for pointer, the * comes from C.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜