나름 프로그래밍?/ Objective-C

[super setFillColor: c];

알 수 없는 사용자 2010. 1. 28. 18:14
@implementation Circle
- (void) setFillColor: (ShapeColor) c
{
   if (c == kRedColor){
      c = kGreenColor;
  }

  [super setFillColor: c];
} // setFillColor
// and the rest of the Circle @implementation
// is unchanged
@end // Circle

------------------------------------------

빨간 원을 녹색 원으로 바꾸는 소스이다. setFillColor: 가 Shape에 정의되어 있는 경우,
super를 사용해서 수퍼클래스(Shape)에게 fillColor의 인스턴스 변수에 변경된 색을 저장할 수 있도록 할 수 있다.
(super에 메시지를 보내면 Objective-C에게 그 클래스의 수퍼클래스에 메시지를 보내라고 요청하는 것이 된다.)