Skip to content

ObjectiveC:DefaultClassTemplate

Objective-C의 클래스의 기본 형태는 Foundation.hNSObject를 상속받는다.

Header file

#import <Foundation/Foundation.h>

@interface TestClass : NSObject
{
@private
    int _x;
    int _y;
}

- (void) setAttributeWithX: (int) x andY: (int) y;
- (int) getAttributeX;
- (int) getAttributeY;

@end

Source file

#import "header file path"

@implementation TestClass

// constructor
- (id) init
{
    if (self = [super init]) {
        // init member ...
    }

    return self;
}

// destructor
- (void) dealloc
{
    // release member ...
    [super dealloc];
}

- (void) setAttributeWithX: (int) x andY: (int) y
{
    _x = x;
    _y = y;
}

- (int) getAttributeX
{
    return _x;
}

- (int) getAttributeY
{
    return _y;
}

@end

See also