Call a class method from within that class Call a class method from within that class objective-c objective-c

Call a class method from within that class


In a class method, self refers to the class being messaged. So from within another class method (say classMethodB), use:

+ (void)classMethodB{    // ...    [self classMethodA];    // ...}

From within an instance method (say instanceMethodB), use:

- (void)instanceMethodB{    // ...    [[self class] classMethodA];    // ...}

Note that neither presumes which class you are messaging. The actual class may be a subclass.


Should be as simple as:

[MyClass classMethodA];

If that's not working, make sure you have the method signature defined in the class's interface. (Usually in a .h file)


In objective C 'self' is used to call other methods within the same class.

So you just need to write

+classMethodB{    [self classMethodA];}