What is the safe and correct way of calling a class method from an instance method in objective - C ?
Asked
Active
Viewed 150 times
2 Answers
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
-
Which one is the best practice ? Are there any other issues i need to be aware of (other than inheritance) ? – Samhan Salahuddin Dec 27 '12 at 11:51
-
There are no issues, both ways are correct, the first is just used when you have subclasses – Ismael Dec 27 '12 at 11:52