What is the difference between class and instance methods?

后端 未结 18 2190
说谎
说谎 2020-11-21 11:55

What\'s the difference between a class method and an instance method?

Are instance methods the accessors (getters and setters) while class methods are pretty much ev

18条回答
  •  伪装坚强ぢ
    2020-11-21 12:37

    Adding to above answers

    Class method will work on class, we will use this for general purpose where like +stringWithFormat, size of class and most importantly for init etc

    NSString *str = [NSString stringWithFormat:@"%.02f%%",someFloat]; 
    

    Instance Method will work on an instance of a class not on a class like we are having two persons and we want to get know the balance of each separately here we need to use instance method. Because it won't return general response. e.g. like determine the count of NSSArray etc.

    [johnson getAccountBalance];
    [ankit getAccountBalance];
    

提交回复
热议问题