區別是前者會調用setName方法,後者只是賦值。
-(void)setName:(NSString*)newName//setter方法
{
[newName retain];
[name relase];
[name=newName;
}
如果(no_arc)
obj=[[Class alloc]init];
obj1=obj;
[obj release];//已釋放
會出錯
正確編碼應該是:
obj=[[Class alloc]init];
obj1=obj;
[obj1 retain];
/*
*或self.obj1=obj;
*/
[obj release];