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 */; };
34EFC7781B701D3100AD841F /* ASStackUnpositionedLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED4A1B17847A00DA7C62 /* ASStackUnpositionedLayout.mm */; };
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, ); }; };
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 */; };

View File

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

View File

@@ -8,7 +8,17 @@
#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
@@ -32,12 +42,3 @@
@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>
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> {
@interface ASPagerNode () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout, ASDelegateProxyInterceptor> {
UICollectionViewFlowLayout *_flowLayout;
ASPagerNodeProxy *_proxy;
id <ASPagerNodeDataSource> _pagerDataSource;
@@ -20,6 +20,7 @@
@end
@implementation ASPagerNode
@dynamic delegate;
- (instancetype)init
{
@@ -50,10 +51,15 @@
if (pagerDataSource != _pagerDataSource) {
_pagerDataSource = pagerDataSource;
_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
{
return _pagerDataSource;

View File

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

View File

@@ -21,19 +21,31 @@
@end
@interface ASTableView ()
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass;
@end
@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 nil;
}
- (instancetype)initWithStyle:(UITableViewStyle)style
{
return [self _initWithStyle:style dataControllerClass:nil];
}
- (instancetype)init
{
return [self _initWithStyle:UITableViewStylePlain dataControllerClass:nil];
}
- (void)didLoad
{
[super didLoad];

View File

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

View File

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

View File

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

View File

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

View File

@@ -52,7 +52,6 @@
if (_willDeallocBlock) {
_willDeallocBlock(self);
}
[super dealloc];
}
@end
@@ -78,7 +77,6 @@
if (_willDeallocBlock) {
_willDeallocBlock(self);
}
[super dealloc];
}
@end
@@ -130,6 +128,7 @@
@implementation ASTableViewTests
// TODO: Convert this to ARC.
- (void)DISABLED_testTableViewDoesNotRetainItselfAndDelegate
{
ASTestTableView *tableView = [[ASTestTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
@@ -149,10 +148,10 @@
tableView.asyncDataSource = delegate;
tableView.asyncDelegate = delegate;
[delegate release];
// [delegate release];
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);
}
@@ -399,6 +398,9 @@
style:UITableViewStylePlain
asyncDataFetching:YES];
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.asyncDataSource = dataSource;