私はObjectiveCを学ぼうとしています。コンパイラが舞台裏で生成する次のコードに出くわしました。@property(nonatomic, retain) NSString* myField
-(NSString*) myField
{
return myField_; //assuming myField_ is the name of the field.
}
-(void) setMyField:(NSString*) newValue
{
if(newValue != myField_)
{
[myField_ release];
myField_ = [newValue retain];
}
}
今私の質問は; newValueでretainを呼び出すのはなぜですか?代わりに、次の構文を使用する必要があります。
myField_ = newValue;
[myField_ retain];
私の理解では、myField_
?が指すオブジェクトを保持したいので、上記の構文が使用されない理由を教えてください。