iOS MRC 下 get set 方法写法

iOS 非ARC下get set 方法写法

iOS arc和mrc下重写set方法

http://blog.csdn.net/aiai_5251/article/details/41695611

ARC下
@property (nonatomic, weak/assign) id<PPWebViewDataDelegate> delegate;
相当于
- (void)setDelegate:(id<PPWebViewDataDelegate>)delegate
{
    if (_delegate != delegate) {
        _delegate = delegate;
    }
}
MRC下
@property (nonatomic, strong/retain/copy) id<PPWebViewDataDelegate> delegate;
相当于

- (void)setDelegate:(id<PPWebViewDataDelegate>)delegate
{
    if (_delegate != delegate) {
        [_delegate release];
        _delegate = [delegate retain/copy];
    }
}

http://blog.csdn.net/aiai_5251/article/details/41695611

MRC的set和get

set方法:

-(void)setName:(NSString *)name

{

  if (_name != name)

  {

   [_name release];

   [name retain];

         _name = name;

       }

}

凡是.h里面的带星号变量或者属性的都要在dealloc中release一下 [_name release];

这样释放 或者self.xxx = nil;这种更好

get方法:

-(UILabel *)titleLable

{

    if (_titleLable == nil)

    {

             _titleLable = [[UILabelalloc]init];

          } return_titleLable;

}

在get方法中初始化,当调用的时候初始化


你可能感兴趣的:(iOS MRC 下 get set 方法写法)