Language/iPhone

(+)와 (-)함수의 차이는?

태하팍 2012. 3. 26. 17:28
반응형

 



//

//  main.m

//  demoClassInstance

//

//  Created by SDS107 on 12. 3. 26..

//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//


#import <Foundation/Foundation.h>


@interface DemoInstance : NSObject

+(void)ClassMethod;

-(void)instanceMethod;

@end


@implementation DemoInstance

+(void)ClassMethod

{

    NSLog(@"클래스에서 직접 호출");

}

-(void)instanceMethod

{

    NSLog(@"인스턴스에서 직접 호출");

}

@end



int main(int argc, const char * argv[])

{

    

    [DemoInstance ClassMethod];    // 객체를 생성하지 않아도 호출 있다

    

    DemoInstance *demo = [DemoInstance new];

    [demo instanceMethod];   // 객체를 만들고 뒤에 호출 한다. 대부분의 방식이다.

    

    return 0;

}


반응형