Question

Question: How to call superclass static method ?

I mean directly by using:

[SuperClassName method]

OR

There is any other way existed?

Was it helpful?

Solution

If you wants to call drive class methods from base class then, declare class method in your drive class like this: using (+) sign before method name.

+(void)myClassMethod;

Call this method from base class like this:

[YourDriveClassName myClassMethod];

Or you wants to call drive class instance methods from base class, declare instance method in your drive class using (-)sign before method name.

-(void)sayHelloToSomeOne:(NSString *)greeting;

Call this method from base class.

[super sayHelloToSomeOne:@"Hello Worlds!"];

OTHER TIPS

In Objective-C, there are two type of Methods:

1) Class Method

e.g:

+ (void)aClassMethod;

You can call this method by his class name like : [MyClass aClassMethod]

2) Instance Method

e.g:

- (void)anInstanceMethod;

You can call this method by his class's instance name like :

MyClass *object = [[MyClass alloc] init]; [object anInstanceMethod];

Hope this will helps you.

If the call is from a static method. That is

+ (void)someMethod{
  [self method];
}

if call is from an instance method it is really required to call it like

- (void)someMethod{
  [SuperClassName method];
}

You will declare a class level method in iOS to use "+" before the method declaration.

declared in your class.h file

+ (void)yourStaticMethod;

// call is from anywhere

[yourClassName myStaticMethod];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top