我在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