반응형

Objective C --  문법정리 : 함수, 메소드


참고 : http://www.tutorialspoint.com/objective_c/objective_c_functions.htm

          http://rypress.com/tutorials/objective-c/methods

          http://roadfiresoftware.com/2014/06/how-to-read-and-write-method-declarations-in-objective-c/

          http://roadfiresoftware.com/2014/06/how-to-send-messages-aka-call-methods-in-objective-c/




함수 == 메소드



- (return Type) 함수이:(Type)parameter1, 별칭:(Type) parameter2,... , 별칭:(Type) parametern

   {

        // 함수 body

   }



< 함수 선언의 예 >


-(int) max:(int)num1 andNum2:(int)num2;



< 사용 예 >


// Action methods

- (void)startEngine;

- (void)driveForDistance:(double)theDistance;

- (void)driveFromOrigin:(id)theOrigin toDestination:(id)theDestination;



** 다른 언어와 비교하기


// Python/Java/C++

porsche.drive("Home", "Airport");


// Objective-C

[porsche driveFromOrigin:@"Home" toDestination:@"Airport"];








// instantiate our objects

CarController *carController = [[CarController alloc] init];

Car *car = [[Car alloc] init];

Person *person = [[Person alloc] init];

 

// send a message with no arguments

[carController driveCar];

 

// send a message with one argument

[carController driveCar:car];

 

// send a message with two arguments

[carController driveCar:car withPerson:person];






  < 출처 : http://roadfiresoftware.com/2014/06/how-to-read-and-write-method-declarations-in-objective-c/ >








반응형
Posted by 자유프로그램
,