我在UITableView的头文件中发现了这个属性,并且几乎每个属性都是非弧样式,尽管我的项目正在使用ARC。为什么UITableView的委托属性的属性很弱
@property (nonatomic, assign) id <UITableViewDataSource> dataSource;
@property (nonatomic, assign) id <UITableViewDelegate> delegate;
为什么苹果不使用的,而不是assign
weak
属性,它是对非弧形向后兼容?如果是这样,为什么不使用__has_feature(objc_arc)
来区分ARC和非ARC。
#if __has_feature(objc_arc)
@property (nonatomic, weak) id <UITableViewDataSource> dataSource;
@property (nonatomic, weak) id <UITableViewDelegate> delegate;
#else
@property (nonatomic, assign) id <UITableViewDataSource> dataSource;
@property (nonatomic, assign) id <UITableViewDelegate> delegate;
#endif
我希望delegate
较弱,所以我不需要当委托实例被释放委托设置为零。
感谢您的帮助。
编辑:
我注意到,__has_feature(objc_arc)
是错误的,因为我可以使用ARC时,我的部署目标为4.3,但后来我不能使用weak
。所以条件应该是我的部署目标是否等于5.0或更高。
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
@property (nonatomic, weak) id <UITableViewDataSource> dataSource;
@property (nonatomic, weak) id <UITableViewDelegate> delegate;
#else
@property (nonatomic, assign) id <UITableViewDataSource> dataSource;
@property (nonatomic, assign) id <UITableViewDelegate> delegate;
#endif
请参阅我的解释:http://stackoverflow.com/a/24469143/341994它不是“向后兼容非ARC”;它不是ARC。 – matt 2014-12-04 01:20:39
@matt非常感谢。你认为苹果公司使用'#if__IPHONE_OS_VERSION_MIN_REQUIRED> = __IPHONE_5_0'来提供更好的支持ARC的Cocoa会更好吗?或者很难做到这一点。 – KudoCC 2014-12-04 01:32:55
可可的这些部分都很陈旧。他们不会很快改变。他们在ARC之前多年。他们是他们。继续。 – matt 2014-12-04 01:58:35