Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a obj-c method with a parameter

I've change a c-style function to an objective-c method. As a method, how do i use it?

    NSString* myfunc( int x )

       is now:

    - (NSString *)myFuncWithParam:(int)x


 c code:  myString = myfunc(x);  // works

 obj-c code: myString = myFuncWithParam(x); // fails to compile. 

From one of the answers: myString = [object myFuncWithParam:x];

In that case, what would "object" be?

like image 248
Alan Avatar asked Mar 03 '09 18:03

Alan


1 Answers

myString = [object myFuncWithParam:x];

Where object is the object which has the method you're calling. If you're calling it from the same object, you'll use 'self'. This tutorial might help you out in learning Obj-C.

like image 70
Marc Charbonneau Avatar answered Oct 04 '22 12:10

Marc Charbonneau