How to call static methods of a parent class in Objective-C.

Question: How to call a superclass static method ?

I mean directly using:

[SuperClassName method]

OR

Is there any other way?

+4
source share
4 answers

If you want to call disk class methods from a base class, declare the class method in your disk class as follows: using the (+) sign in front of the method name.

+(void)myClassMethod;

Call this method from the base class as follows:

[YourDriveClassName myClassMethod];

, , (-) .

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

.

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

Objective-C :

1)

:

+ (void)aClassMethod;

, : [MyClass aClassMethod]

2)

:

- (void)anInstanceMethod;

, :

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

, .

+1

.

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

,

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

iOS "+" .

class.h

+ (void)yourStaticMethod;

//

[yourClassName myStaticMethod];
0
source

Source: https://habr.com/ru/post/1532285/


All Articles