Class Method and Instance Method in Objective-C

Class Method in Objective-C:

A class method is one that performs some operation on the class itself, such as creating a new instance of the class. It has the following syntax:


Instance Method in Objective-C:

A unique occurrence of a class is an instance, and the actions that are performed on the instance are called the instance method. In some cases, a method can be applied to an instance of the class or to the class itself. An instance method performs some operation on a particular instance of a class, such as setting its value, retrieving its value, displaying its value, and so on. It has the following syntax:

[Instance-method ];

In this above syntax, a left bracket is followed by the name of a class or instance of that class, which is followed by one or more spaces, which is followed by the method you want to perform. Finally, it is closed off with a right bracket and a terminating semicolon. When you ask a class or an instance to perform some action, you say that you are sending it a message. The recipient of that message is called the receiver. So another way to look at the general syntax given as follows:

[receiver message];