打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
property写在.h和.m中的区别
做ios开发也有一年多了,以前都是很中规中矩的,在头文件中写property,在实现文件中写成员变量。
不过前一阵发现几个app,在实现文件中的interface里也会写property,然后重写属性的getter方法,调用这个属性的时候用self调用
想问一下有什么区别吗?或者在.h中的{}写变量
  



@end


#import 'ViewController.h'

@interface ViewController ()
{
UIView *_view;
}
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

_view = [[UIView alloc] initWithFrame:self.view.bounds];
_view.backgroundColor = [UIColor redColor];
[self.view addSubview:_view];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}



@end


#import 'ViewController.h'

@interface ViewController ()
@property (nonatomic, strong) UIView *redView;
@end

@implementation ViewController

- (UIView *)view
{
if (!_redView) {
_redView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_redView.backgroundColor = [UIColor redColor];
}
return _redView;
}
- (void)viewDidLoad {
[super viewDidLoad];


[self.view addSubview:self.redView];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}

@end

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于@property及@synthesize以两Demo简单说明
让你的代码自动格式化
再见,viewDidUnload方法
viewDidUnload 和 viewWillUnload 被废弃之后的内存警告处理
iOS Masonry使用案例讲解 | 发光的我
IOS UI 第四篇:基本UI
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服