0

What is the safe and correct way of calling a class method from an instance method in objective - C ?

2 Answers 2

2

you can do like:

- (void)your_instanceMethodB
{

    [[self class] your_classMethodA];

}  

READ this: Call a class method from within that class . Jon Reid and others answers.

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

2 Comments

Thanks for the pointer . So should i remove the question as a duplicate ?
@eddardstark : your should read this ..I think you can flag for deletion but can't delete your self.
1

If you are using subclasses and your subclass overrides the method, then you should do

 [[self class] myFunction];

If not, the standard way is correct

[MyClass myFunction];

2 Comments

Which one is the best practice ? Are there any other issues i need to be aware of (other than inheritance) ?
There are no issues, both ways are correct, the first is just used when you have subclasses

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.