开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜