I found this in the UITableView header file, and almost every property is non-arcane, although my project uses ARC.
@property (nonatomic, assign) id <UITableViewDataSource> dataSource; @property (nonatomic, assign) id <UITableViewDelegate> delegate;
Why doesn't Apple use the weak
property instead of assign
, is it backward compatible for non-arcs? If so, why not use __has_feature(objc_arc)
to distinguish between ARC and non-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
I hope the delegate
is weak, so I don't need to set the delegate to zero when the delegate instance is freed.
Thank you for your help.
Edit:
I note that __has_feature(objc_arc)
incorrect because I can use ARC when my deployment target is 4.3, but then I cannot use weak
. So the condition should be: my deployment target is 5.0 or higher.
#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
source share