페이지

2012년 9월 25일 화요일

Objective-C setter method


@property(nonatomic,retain) NSObject * exVal;

@synthesize exVal;

- (void)setExVal:(NSObject*) val {
   [exVal release]; 
   exVal = [val retain];
}




this is wrong. coz if val is equal to exVal, both exVal and val are released. and then nil retain.






- (void)setExVal:(NSObject*) val {
    [val retain];
    [exVal release];
    exVal = val;
}

this is right.


댓글 없음:

댓글 쓰기