开发者

What's the difference between -(void) and +(void) methods [duplicate]

开发者 https://www.devze.com 2023-01-25 21:43 出处:网络
This question already has answers here: Closed 12 years ago. 开发者_开发问答 Possible Duplicate: What do the plus and minus signs mean in Objective C next to a method?
This question already has answers here: Closed 12 years ago. 开发者_开发问答

Possible Duplicate:

What do the plus and minus signs mean in Objective C next to a method?

Had an error which I fixed by changing -(void) to +(void), but I would like the understand it.

Thanks.


This denotes an instance method. You must hold a valid instance of the class to call this method.

-(void)

This denotes a class method. You do not need an instance of the class to call this method.

+(void)


- methods are instance methods and called on a specific instance of a class.

While + methods are class methods and called on the class itself.

0

精彩评论

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