개체 생성

개체 생성은 [[NSObject alloc] init] 패턴을 사용합니다. alloc 메서드는 메모리를 할당하고, 초기화는 init... 메서드가 담당합니다. ‘생성자’ 역할은 init... 메서드가 담당하죠.

그래서 커스텀 초기화를 수행하려면 init... 메서드를 오버라이드해 사용합니다. init... 메서드는 기본적인 사용 패턴이 있으면 그 패턴은 다음과 같습니다.

- (id) init
{
	self = [super init]
	if(self!=nil)
	{
		// Do something here.
	}
	return self;
}

개체 소멸

개체 소멸 시점에 처리해야 할 일이 있다면 dealloc 메서드를 오버라이드하면 됩니다. dealloc 의 사용 패턴은 다음과 같습니다.

- (void) dealloc
{
	// Do something here.
	[super dealloc];
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>