开发者

class methods or static variable, what's the difference?

开发者 https://www.devze.com 2023-03-21 09:27 出处:网络
i\'m a bit l开发者_JAVA百科ost with the class methods, and \"static\" variables : what is the difference? for example, in a script with a mapView, we have this :

i'm a bit l开发者_JAVA百科ost with the class methods, and "static" variables : what is the difference? for example, in a script with a mapView, we have this :

+(CGFloat)annotationPadding;

{

return 10.0f;

}

Why do we use this class method instead of a static variable, if the only we want is "the same value for that class" ?

Thanks

Paul


A class method is to a static variable what an instance method is to an instance variable.

One is a method that can do processing, the other is a variable that can hold - or point to - data.

You'd use a class method for convenience usage like e.g. NSMutableArray does with the array class method, or for processing that doesn't require the object's state to do the task.

0

精彩评论

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

关注公众号