-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?

4
  • 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 ... Commented Oct 26, 2015 at 8:09
  • Directly we are calling through the class name is class method and some restriction are there pls refer this link stackoverflow.com/questions/1053592/… class methods- it is just like a static method Commented Oct 26, 2015 at 8: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. Commented Oct 26, 2015 at 8:25
  • Hope this helps you: Purpose of Instance Methods vs. Class Methods in Objective-C , Commented Oct 26, 2015 at 8:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.