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.
精彩评论