开发者社区 问答 正文

请问在非ARC中重写setget方法为何一只报错 ?

@interface Boy : NSObject
 {
 Gun *gun;
 }

-(void)setGun:(Gun *)gun;
 -(Gun *)gun;

@end
 @implementation Boy

- (void)dealloc
{
    NSLog(@"Boy释放");
    [super dealloc];
}
-(void)setGun:(Gun *)gun
{
    _gun=gun;
}
-(Gun *)gun{

    return _gun;
}

展开
收起
爵霸 2016-03-11 08:15:22 1766 分享 版权
1 条回答
写回答
取消 提交回答
  • (void)setGun:(Gun *)gun { if (_gun!= gun) { [_gun release]; gun = [gun retain/copy]; } } 希望能帮到你!

    2019-07-17 18:58:15
    赞同 展开评论
问答地址: