开发者社区> 问答> 正文

属性(property)与成员变量(ivar)有什么区别

最近看了很多别人写的example,一直搞不懂为什么很多人同时写属性和成员变量
如下:

@interface KKProgressToolbar : UIToolbar {
    @private

    id <KKProgressToolbarDelegate> __weak _actionDelegate;

    UIBarButtonItem* _stopButtonItem;
    UIActivityIndicatorView* _activityIndicator;
    UILabel* _statusLabel;
    UIProgressView* _progressBar;
}

@property (nonatomic, strong) UIBarButtonItem *stopButtonItem;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UIProgressView *progressBar;

@property (nonatomic, weak) id <KKProgressToolbarDelegate> actionDelegate;
一般我自己写的时候,直接写@property, 然后在m文件中,写上

@synthesize aaaaa = _aaaaa;

我刚开始学IOS,不知道这个的区别是什么,望有人不嫌弃,指点一二,在此谢过!!!

展开
收起
a123456678 2016-07-20 14:51:48 1765 0
2 条回答
写回答
取消 提交回答
  • 强!
    2019-07-17 19:58:52
    赞同 展开评论 打赏
  • 成员变量主要是适用于iOS5之前的开发,需要程序员手动进行内存管理。iOS5之后(包括iOS5)引入了ARC(Automatic Reference Counting)同过在property中使用strong,weak等标记自动对内存进行管理。也就是说进行iOS5及以后系统版本的开发,可以放心的使用property,而无需对其进行手动的内存管理。

    2019-07-17 19:58:52
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载