objective-c 함수

iOS/Objective-C 2018. 12. 12. 17:47
728x90

Objective-C 함수에 대해 간략하게 적어둔다.


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

   {

        // 함수 body

   }



#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


// 함수

/* 리턴값이 없고 매개변수도 없는 함수

 - (void) 함수명 {

   do something ...

 }

 */

// 함수 호출

// [self 함수명];


/*

 // 매겨변수는 있고 리턴값은 없는 함수

 - (return Type) 함수명 : (매개변수 타입) 매겨변수명1

   두번째 값에 대한 설명:(매개변수 타입) 매겨변수명2

 {

    return Type 있으면 return returnValue;

    return Type 없으면 , void 리턴이 없음.

 }

 */


- (void) sumFunction1 : (NSInteger) firstValue {

    NSLog(@" 더하기 = %li", firstValue + 10);

}


- (void) sumFunction2 : (NSInteger) firstValue

      withValue:(NSInteger) secondValue

{

    NSLog(@"firsrtValue + secondValue = %li", firstValue + secondValue);

}


- (NSInteger) sumFunction3 : (NSInteger) firstValue

                  withValue:(NSInteger) secondValue

{

    NSInteger returnValue = firstValue + secondValue;

    return returnValue;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    // 함수에서 원하는 매개변수의 타입과 내가 함수를 호출하면서 넣어주는 값의 타입을 맞춰야 한다.

    [self sumFunction1:30];

    

    [self sumFunction2:10 withValue:30];

    

    NSLog(@"리턴값이 있는 함수 결과 : %li", [self sumFunction3:10 withValue:30]);

    

    }


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



'iOS > Objective-C' 카테고리의 다른 글

objective-c UIView 기초  (0) 2018.12.17
objective-c 객체 Type  (0) 2018.12.15
objective C 변수 타입  (0) 2018.12.09
NSLog  (0) 2018.03.01
모바일 Web을 위한 아이콘 변환 사이트  (0) 2017.05.24
블로그 이미지

Link2Me

,