Delegate definition tweaks for Table and Collection; ensure Table tests run with ARC enabled.

This commit is contained in:
Scott Goodson
2015-12-24 21:41:12 -08:00
parent c1640c7f59
commit 7ece41ff64
11 changed files with 79 additions and 54 deletions

View File

@@ -242,7 +242,7 @@
34EFC7771B701D2D00AD841F /* ASStackUnpositionedLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED491B17847A00DA7C62 /* ASStackUnpositionedLayout.h */; }; 34EFC7771B701D2D00AD841F /* ASStackUnpositionedLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED491B17847A00DA7C62 /* ASStackUnpositionedLayout.h */; };
34EFC7781B701D3100AD841F /* ASStackUnpositionedLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED4A1B17847A00DA7C62 /* ASStackUnpositionedLayout.mm */; }; 34EFC7781B701D3100AD841F /* ASStackUnpositionedLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED4A1B17847A00DA7C62 /* ASStackUnpositionedLayout.mm */; };
34EFC7791B701D3600AD841F /* ASLayoutSpecUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED451B17847A00DA7C62 /* ASLayoutSpecUtilities.h */; }; 34EFC7791B701D3600AD841F /* ASLayoutSpecUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED451B17847A00DA7C62 /* ASLayoutSpecUtilities.h */; };
3C9C128519E616EF00E942A0 /* ASTableViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9C128419E616EF00E942A0 /* ASTableViewTests.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 3C9C128519E616EF00E942A0 /* ASTableViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9C128419E616EF00E942A0 /* ASTableViewTests.m */; };
430E7C8F1B4C23F100697A4C /* ASIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 430E7C8D1B4C23F100697A4C /* ASIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; }; 430E7C8F1B4C23F100697A4C /* ASIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 430E7C8D1B4C23F100697A4C /* ASIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; };
430E7C901B4C23F100697A4C /* ASIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 430E7C8D1B4C23F100697A4C /* ASIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; }; 430E7C901B4C23F100697A4C /* ASIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 430E7C8D1B4C23F100697A4C /* ASIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; };
430E7C911B4C23F100697A4C /* ASIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 430E7C8E1B4C23F100697A4C /* ASIndexPath.m */; }; 430E7C911B4C23F100697A4C /* ASIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 430E7C8E1B4C23F100697A4C /* ASIndexPath.m */; };

View File

@@ -15,8 +15,8 @@
#import <AsyncDisplayKit/ASCollectionViewFlowLayoutInspector.h> #import <AsyncDisplayKit/ASCollectionViewFlowLayoutInspector.h>
@class ASCellNode; @class ASCellNode;
@protocol ASCollectionViewDataSource; @protocol ASCollectionDataSource;
@protocol ASCollectionViewDelegate; @protocol ASCollectionDelegate;
@protocol ASCollectionViewLayoutInspecting; @protocol ASCollectionViewLayoutInspecting;
/** /**
@@ -35,8 +35,8 @@
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout; - (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout;
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout; - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;
@property (nonatomic, weak) id<ASCollectionViewDataSource> asyncDataSource; @property (nonatomic, weak) id<ASCollectionDelegate> asyncDelegate;
@property (nonatomic, weak) id<ASCollectionViewDelegate> asyncDelegate; // must not be nil @property (nonatomic, weak) id<ASCollectionDataSource> asyncDataSource;
/** /**
* Tuning parameters for a range type. * Tuning parameters for a range type.
@@ -286,9 +286,8 @@
/** /**
* This is a node-based UICollectionViewDataSource. * This is a node-based UICollectionViewDataSource.
*/ */
@protocol ASCollectionDataSource <ASCollectionViewDataSource> #define ASCollectionViewDataSource ASCollectionDataSource
@end @protocol ASCollectionDataSource <ASCommonCollectionViewDataSource, NSObject>
@protocol ASCollectionViewDataSource <ASCommonCollectionViewDataSource, NSObject>
/** /**
* Similar to -collectionView:cellForItemAtIndexPath:. * Similar to -collectionView:cellForItemAtIndexPath:.
@@ -349,9 +348,8 @@
/** /**
* This is a node-based UICollectionViewDelegate. * This is a node-based UICollectionViewDelegate.
*/ */
@protocol ASCollectionDelegate <ASCollectionViewDelegate> #define ASCollectionViewDelegate ASCollectionDelegate
@end @protocol ASCollectionDelegate <ASCommonCollectionViewDelegate, NSObject>
@protocol ASCollectionViewDelegate <ASCommonCollectionViewDelegate, NSObject>
@optional @optional

View File

@@ -8,7 +8,17 @@
#import <AsyncDisplayKit/ASCollectionNode.h> #import <AsyncDisplayKit/ASCollectionNode.h>
@protocol ASPagerNodeDataSource; @class ASPagerNode;
@protocol ASPagerNodeDataSource <ASCollectionDataSource>
// This method replaces -collectionView:numberOfItemsInSection:
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode;
// This method replaces -collectionView:nodeForItemAtIndexPath:
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
@end
@interface ASPagerNode : ASCollectionNode @interface ASPagerNode : ASCollectionNode
@@ -32,12 +42,3 @@
@end @end
@protocol ASPagerNodeDataSource <NSObject>
// This method replaces -collectionView:numberOfItemsInSection:
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode;
// This method replaces -collectionView:nodeForItemAtIndexPath:
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
@end

View File

@@ -11,7 +11,7 @@
#import <AsyncDisplayKit/AsyncDisplayKit.h> #import <AsyncDisplayKit/AsyncDisplayKit.h>
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> { @interface ASPagerNode () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout, ASDelegateProxyInterceptor> {
UICollectionViewFlowLayout *_flowLayout; UICollectionViewFlowLayout *_flowLayout;
ASPagerNodeProxy *_proxy; ASPagerNodeProxy *_proxy;
id <ASPagerNodeDataSource> _pagerDataSource; id <ASPagerNodeDataSource> _pagerDataSource;
@@ -20,6 +20,7 @@
@end @end
@implementation ASPagerNode @implementation ASPagerNode
@dynamic delegate;
- (instancetype)init - (instancetype)init
{ {
@@ -50,10 +51,15 @@
if (pagerDataSource != _pagerDataSource) { if (pagerDataSource != _pagerDataSource) {
_pagerDataSource = pagerDataSource; _pagerDataSource = pagerDataSource;
_proxy = pagerDataSource ? [[ASPagerNodeProxy alloc] initWithTarget:pagerDataSource interceptor:self] : nil; _proxy = pagerDataSource ? [[ASPagerNodeProxy alloc] initWithTarget:pagerDataSource interceptor:self] : nil;
super.dataSource = _proxy; super.dataSource = (id <ASCollectionDataSource>)_proxy;
} }
} }
- (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy
{
[self setDataSource:nil];
}
- (id <ASPagerNodeDataSource>)dataSource - (id <ASPagerNodeDataSource>)dataSource
{ {
return _pagerDataSource; return _pagerDataSource;

View File

@@ -14,7 +14,8 @@
*/ */
@interface ASTableNode : ASDisplayNode @interface ASTableNode : ASDisplayNode
- (instancetype)initWithStyle:(UITableViewStyle)style NS_DESIGNATED_INITIALIZER; - (instancetype)init; // UITableViewStylePlain
- (instancetype)initWithStyle:(UITableViewStyle)style;
@property (nonatomic, readonly) ASTableView *view; @property (nonatomic, readonly) ASTableView *view;

View File

@@ -21,19 +21,31 @@
@end @end
@interface ASTableView () @interface ASTableView ()
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style; - (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass;
@end @end
@implementation ASTableNode @implementation ASTableNode
- (instancetype)initWithStyle:(UITableViewStyle)style - (instancetype)_initWithStyle:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass
{ {
if (self = [super initWithViewBlock:^UIView *{ return [[ASTableView alloc] _initWithFrame:CGRectZero style:style]; }]) { if (self = [super initWithViewBlock:^UIView *{ return [[ASTableView alloc] _initWithFrame:CGRectZero
style:style
dataControllerClass:dataControllerClass]; }]) {
return self; return self;
} }
return nil; return nil;
} }
- (instancetype)initWithStyle:(UITableViewStyle)style
{
return [self _initWithStyle:style dataControllerClass:nil];
}
- (instancetype)init
{
return [self _initWithStyle:UITableViewStylePlain dataControllerClass:nil];
}
- (void)didLoad - (void)didLoad
{ {
[super didLoad]; [super didLoad];

View File

@@ -7,17 +7,14 @@
*/ */
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <AsyncDisplayKit/ASRangeController.h> #import <AsyncDisplayKit/ASRangeController.h>
#import <AsyncDisplayKit/ASTableViewProtocols.h> #import <AsyncDisplayKit/ASTableViewProtocols.h>
#import <AsyncDisplayKit/ASBaseDefines.h> #import <AsyncDisplayKit/ASBaseDefines.h>
#import <AsyncDisplayKit/ASBatchContext.h> #import <AsyncDisplayKit/ASBatchContext.h>
@class ASCellNode; @class ASCellNode;
@protocol ASTableViewDataSource; @protocol ASTableDataSource;
@protocol ASTableViewDelegate; @protocol ASTableDelegate;
/** /**
* Node-based table view. * Node-based table view.
@@ -27,8 +24,8 @@
*/ */
@interface ASTableView : UITableView @interface ASTableView : UITableView
@property (nonatomic, weak) id<ASTableViewDelegate> asyncDelegate; // must not be nil @property (nonatomic, weak) id<ASTableDelegate> asyncDelegate;
@property (nonatomic, weak) id<ASTableViewDataSource> asyncDataSource; @property (nonatomic, weak) id<ASTableDataSource> asyncDataSource;
/** /**
* Initializer. * Initializer.
@@ -280,9 +277,8 @@
/** /**
* This is a node-based UITableViewDataSource. * This is a node-based UITableViewDataSource.
*/ */
@protocol ASTableDataSource <ASTableViewDataSource> #define ASTableViewDataSource ASTableDataSource
@end @protocol ASTableDataSource <ASCommonTableViewDataSource, NSObject>
@protocol ASTableViewDataSource <ASCommonTableViewDataSource, NSObject>
/** /**
* Similar to -tableView:cellForRowAtIndexPath:. * Similar to -tableView:cellForRowAtIndexPath:.
@@ -326,9 +322,8 @@
* Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are * Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are
* responsible for deciding their preferred onscreen height in -calculateSizeThatFits:. * responsible for deciding their preferred onscreen height in -calculateSizeThatFits:.
*/ */
@protocol ASTableDelegate <ASTableViewDelegate> #define ASTableViewDelegate ASTableDelegate
@end @protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject>
@protocol ASTableViewDelegate <ASCommonTableViewDelegate, NSObject>
@optional @optional

View File

@@ -21,6 +21,8 @@
#import "ASLayoutController.h" #import "ASLayoutController.h"
#import "ASRangeController.h" #import "ASRangeController.h"
#import <CoreFoundation/CoreFoundation.h>
static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
//#define LOG(...) NSLog(__VA_ARGS__) //#define LOG(...) NSLog(__VA_ARGS__)
@@ -80,6 +82,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
#pragma mark - #pragma mark -
#pragma mark ASTableView #pragma mark ASTableView
@interface ASTableNode ()
- (instancetype)_initWithStyle:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass;
@end
@interface ASTableView () <ASRangeControllerDataSource, ASRangeControllerDelegate, ASDataControllerSource, _ASTableViewCellDelegate, ASCellNodeLayoutDelegate, ASDelegateProxyInterceptor> { @interface ASTableView () <ASRangeControllerDataSource, ASRangeControllerDelegate, ASDataControllerSource, _ASTableViewCellDelegate, ASCellNodeLayoutDelegate, ASDelegateProxyInterceptor> {
ASTableViewProxy *_proxyDataSource; ASTableViewProxy *_proxyDataSource;
ASTableViewProxy *_proxyDelegate; ASTableViewProxy *_proxyDelegate;
@@ -168,17 +174,21 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass asyncDataFetching:(BOOL)asyncDataFetchingEnabled - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass asyncDataFetching:(BOOL)asyncDataFetchingEnabled
{ {
ASTableNode *tableNode = [[ASTableNode alloc] initWithStyle:style]; // ASTableNode *tableNode = [[ASTableNode alloc] _initWithStyle:style dataControllerClass:dataControllerClass];
tableNode.frame = frame; // tableNode.frame = frame;
return tableNode.view; // return tableNode.view;
return [self _initWithFrame:frame style:style dataControllerClass:dataControllerClass];
} }
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style - (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass
{ {
if (!(self = [super initWithFrame:frame style:style])) if (!(self = [super initWithFrame:frame style:style]))
return nil; return nil;
[self configureWithDataControllerClass:[self.class dataControllerClass] asyncDataFetching:NO]; if (!dataControllerClass) {
dataControllerClass = [self.class dataControllerClass];
}
[self configureWithDataControllerClass:dataControllerClass asyncDataFetching:NO];
return self; return self;
} }

View File

@@ -11,7 +11,7 @@
#import <AsyncDisplayKit/ASDimension.h> #import <AsyncDisplayKit/ASDimension.h>
@class ASCollectionView; @class ASCollectionView;
@protocol ASCollectionViewDelegate; @protocol ASCollectionDelegate;
@protocol ASCollectionViewLayoutInspecting <NSObject> @protocol ASCollectionViewLayoutInspecting <NSObject>
@@ -42,7 +42,7 @@
* *
* @discussion A great time to update perform selector caches! * @discussion A great time to update perform selector caches!
*/ */
- (void)didChangeCollectionViewDelegate:(id<ASCollectionViewDelegate>)delegate; - (void)didChangeCollectionViewDelegate:(id<ASCollectionDelegate>)delegate;
@end @end

View File

@@ -36,7 +36,7 @@
return self; return self;
} }
- (void)didChangeCollectionViewDelegate:(id<ASCollectionViewDelegate>)delegate; - (void)didChangeCollectionViewDelegate:(id<ASCollectionDelegate>)delegate;
{ {
if (delegate == nil) { if (delegate == nil) {
_delegateImplementsReferenceSizeForHeader = NO; _delegateImplementsReferenceSizeForHeader = NO;

View File

@@ -52,7 +52,6 @@
if (_willDeallocBlock) { if (_willDeallocBlock) {
_willDeallocBlock(self); _willDeallocBlock(self);
} }
[super dealloc];
} }
@end @end
@@ -78,7 +77,6 @@
if (_willDeallocBlock) { if (_willDeallocBlock) {
_willDeallocBlock(self); _willDeallocBlock(self);
} }
[super dealloc];
} }
@end @end
@@ -130,6 +128,7 @@
@implementation ASTableViewTests @implementation ASTableViewTests
// TODO: Convert this to ARC.
- (void)DISABLED_testTableViewDoesNotRetainItselfAndDelegate - (void)DISABLED_testTableViewDoesNotRetainItselfAndDelegate
{ {
ASTestTableView *tableView = [[ASTestTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; ASTestTableView *tableView = [[ASTestTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
@@ -148,11 +147,11 @@
tableView.asyncDataSource = delegate; tableView.asyncDataSource = delegate;
tableView.asyncDelegate = delegate; tableView.asyncDelegate = delegate;
[delegate release]; // [delegate release];
XCTAssertTrue(delegateDidDealloc, @"unexpected delegate lifetime:%@", delegate); XCTAssertTrue(delegateDidDealloc, @"unexpected delegate lifetime:%@", delegate);
XCTAssertNoThrow([tableView release], @"unexpected exception when deallocating table view:%@", tableView); // XCTAssertNoThrow([tableView release], @"unexpected exception when deallocating table view:%@", tableView);
XCTAssertTrue(tableViewDidDealloc, @"unexpected table view lifetime:%@", tableView); XCTAssertTrue(tableViewDidDealloc, @"unexpected table view lifetime:%@", tableView);
} }
@@ -399,7 +398,10 @@
style:UITableViewStylePlain style:UITableViewStylePlain
asyncDataFetching:YES]; asyncDataFetching:YES];
ASTableViewFilledDataSource *dataSource = [ASTableViewFilledDataSource new]; ASTableViewFilledDataSource *dataSource = [ASTableViewFilledDataSource new];
#if ! __has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif
tableView.asyncDelegate = dataSource; tableView.asyncDelegate = dataSource;
tableView.asyncDataSource = dataSource; tableView.asyncDataSource = dataSource;