When I create an instance of a class called, say, Sprite, I do something like:
Sprite *mySprite = [[Sprite alloc]开发者_JS百科init];
But why when creating a CGSize or int type variable, I can't use *? Basically, what's the * for?
The * denotes a pointer. CGSize
is declared as a struct
and Sprite
is a class, and in Objective-C all classes are referenced by a pointer.
You can find additional information in the Programming with Objective-C documentation. The relevant sections are Use Pointers to Keep Track of Objects and Methods Can Return Values.
精彩评论