Static method (which is not a class method) in a C object

When reading the IT question and the accepted answer to the question, I was not able to get the difference between the two types of methods. Actually got the point by reading the example, but then I could not write my own static method.

I tried googling to create a static method in object c static methods

What returned the links to this and this question. But, an example here are the CLASS methods according to the first link in the question. What scares me.

Can someone here show me how to create a static method that is not a class method?

Any light on this would be appreciated.

+5
source share
1 answer

The problem you are facing is this: there are no static methods in Obj-C , so you cannot create them.

The difference between static and class methods is the difference between language concepts. You can find static methods in languages ​​like Java or C ++, you will find class methods in languages ​​like Obj-C and Ruby.

The main difference is that

  • Static methods are shared among all instances (this does not exist in Obj-C)

  • A class method is a method for a class. In languages ​​like Obj-C and Ruby, the class itself is an instance of another class (metaclass). Use +before a method declaration means that the method will be defined in the class. Technically, it's just an instance method, just on another object.

, , . , , , .

+18

All Articles