What is the difference between class and instance methods?

后端 未结 18 2161
说谎
说谎 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 12:42

    CLASS METHODS


    A class method typically either creates a new instance of the class or retrieves some global properties of the class. Class methods do not operate on an instance or have any access to instance variable.


    INSTANCE METHODS


    An instance method operates on a particular instance of the class. For example, the accessors method that you implemented are all instance methods. You use them to set or get the instance variables of a particular object.


    INVOKE


    To invoke an instance method, you send the message to an instance of the class.

    To invoke a class method, you send the message to the class directly.


    Source: IOS - Objective-C - Class Methods And Instance Methods

提交回复
热议问题