Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a method inside another method in Objective-C

I'm new to Objective-C.

If I wrote this method declaration in .h

-(void)myMethod;

and this implementation in .m

-(void)myMethod{
    NSLog(@"This is myMethod");
}

How can I call it in my class' viewDidLoad method?

Thank you.

like image 692
user765110 Avatar asked Nov 30 '22 16:11

user765110


2 Answers

Simply just use object "self"

[self myMethod];

like image 164
Cyprian Avatar answered Dec 21 '22 05:12

Cyprian


Assuming that -viewDidLoad is in the same class, use

[self myMethod];

self here is an automatic reference to the current object instance. If you want to call a method on another object stored in a pointer otherObj, it would be

[otherObj myMethod];
like image 25
Seamus Campbell Avatar answered Dec 21 '22 06:12

Seamus Campbell