What is the safe and correct way of calling a class method from an instance method in objective - C ?
2 Answers
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.
2 Comments
Samhan Salahuddin
Thanks for the pointer . So should i remove the question as a duplicate ?
Grijesh Chauhan
@eddardstark : your should read this ..I think you can flag for deletion but can't delete your self.
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
Samhan Salahuddin
Which one is the best practice ? Are there any other issues i need to be aware of (other than inheritance) ?
Ismael
There are no issues, both ways are correct, the first is just used when you have subclasses