-2

"Instance" mean in Objective-C? Kindly tell me where to use Class Method And where to use Instance Method,also tell me where we use (Instacetype) method? why/where we use multi Parameters?

Rayaim
  • 13
  • 9
  • Simply how did you create the object ? NSObject *obj = [[NSObject alloc]init]; In this alloc is the class method and init is the instance method ... – Arun Oct 26 '15 at 08:09
  • Directly we are calling through the class name is class method and some restriction are there pls refer this link http://stackoverflow.com/questions/1053592/what-is-the-difference-between-class-and-instance-methods class methods- it is just like a static method – Arun Oct 26 '15 at 08:15
  • This is too broad for stackoverflow, which is about answering programming questions, not to teach computer science. Buy a book or join a class. – trojanfoe Oct 26 '15 at 08:25
  • Hope this helps you: [Purpose of Instance Methods vs. Class Methods in Objective-C](http://stackoverflow.com/questions/11174526/purpose-of-instance-methods-vs-class-methods-in-objective-c) , – soumya Oct 26 '15 at 08:48

1 Answers1

1

A class method is a method whose self parameter is a reference to the class's class object.

An instance method is a method whose self parameter is a reference to a specific instance of the class.

Those are the technical differences.

A more practical answer is that an instance method operates on a single instance of the class, while a class method operates at a more global, non-specific level. A class method can act as a factory method, such as NSString's stringWithFormat: method. It can also be used to configure behavior that will affect all instances of the class. It can also be used to operate on a collection of instances of the class, such as sorting or filtering.

instancetype is a keyword that can be used as a placeholder for the current class's type. It says to the compiler: pretend that I wrote <my class name> here, so if you see the result of this method assigned somewhere, you know what type it's supposed to be.

Avi
  • 7,469
  • 2
  • 21
  • 22