0

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

Samhan Salahuddin
  • 2,140
  • 1
  • 17
  • 24

2 Answers2

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.

Community
  • 1
  • 1
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
  • Thanks for the pointer . So should i remove the question as a duplicate ? – Samhan Salahuddin Dec 27 '12 at 11:52
  • @eddardstark : your should [read this](http://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled) ..I think you can flag for deletion but can't delete your self. – Grijesh Chauhan Dec 27 '12 at 11:54
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];
Ismael
  • 3,927
  • 3
  • 15
  • 23