Skip to content

Commit 7ece41f

Browse files
author
Scott Goodson
committed
Delegate definition tweaks for Table and Collection; ensure Table tests run with ARC enabled.
1 parent c1640c7 commit 7ece41f

11 files changed

Lines changed: 79 additions & 54 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
34EFC7771B701D2D00AD841F /* ASStackUnpositionedLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED491B17847A00DA7C62 /* ASStackUnpositionedLayout.h */; };
243243
34EFC7781B701D3100AD841F /* ASStackUnpositionedLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED4A1B17847A00DA7C62 /* ASStackUnpositionedLayout.mm */; };
244244
34EFC7791B701D3600AD841F /* ASLayoutSpecUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED451B17847A00DA7C62 /* ASLayoutSpecUtilities.h */; };
245-
3C9C128519E616EF00E942A0 /* ASTableViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9C128419E616EF00E942A0 /* ASTableViewTests.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
245+
3C9C128519E616EF00E942A0 /* ASTableViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9C128419E616EF00E942A0 /* ASTableViewTests.m */; };
246246
430E7C8F1B4C23F100697A4C /* ASIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 430E7C8D1B4C23F100697A4C /* ASIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; };
247247
430E7C901B4C23F100697A4C /* ASIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 430E7C8D1B4C23F100697A4C /* ASIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; };
248248
430E7C911B4C23F100697A4C /* ASIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 430E7C8E1B4C23F100697A4C /* ASIndexPath.m */; };

AsyncDisplayKit/ASCollectionView.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#import <AsyncDisplayKit/ASCollectionViewFlowLayoutInspector.h>
1616

1717
@class ASCellNode;
18-
@protocol ASCollectionViewDataSource;
19-
@protocol ASCollectionViewDelegate;
18+
@protocol ASCollectionDataSource;
19+
@protocol ASCollectionDelegate;
2020
@protocol ASCollectionViewLayoutInspecting;
2121

2222
/**
@@ -35,8 +35,8 @@
3535
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout;
3636
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;
3737

38-
@property (nonatomic, weak) id<ASCollectionViewDataSource> asyncDataSource;
39-
@property (nonatomic, weak) id<ASCollectionViewDelegate> asyncDelegate; // must not be nil
38+
@property (nonatomic, weak) id<ASCollectionDelegate> asyncDelegate;
39+
@property (nonatomic, weak) id<ASCollectionDataSource> asyncDataSource;
4040

4141
/**
4242
* Tuning parameters for a range type.
@@ -286,9 +286,8 @@
286286
/**
287287
* This is a node-based UICollectionViewDataSource.
288288
*/
289-
@protocol ASCollectionDataSource <ASCollectionViewDataSource>
290-
@end
291-
@protocol ASCollectionViewDataSource <ASCommonCollectionViewDataSource, NSObject>
289+
#define ASCollectionViewDataSource ASCollectionDataSource
290+
@protocol ASCollectionDataSource <ASCommonCollectionViewDataSource, NSObject>
292291

293292
/**
294293
* Similar to -collectionView:cellForItemAtIndexPath:.
@@ -349,9 +348,8 @@
349348
/**
350349
* This is a node-based UICollectionViewDelegate.
351350
*/
352-
@protocol ASCollectionDelegate <ASCollectionViewDelegate>
353-
@end
354-
@protocol ASCollectionViewDelegate <ASCommonCollectionViewDelegate, NSObject>
351+
#define ASCollectionViewDelegate ASCollectionDelegate
352+
@protocol ASCollectionDelegate <ASCommonCollectionViewDelegate, NSObject>
355353

356354
@optional
357355

AsyncDisplayKit/ASPagerNode.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88

99
#import <AsyncDisplayKit/ASCollectionNode.h>
1010

11-
@protocol ASPagerNodeDataSource;
11+
@class ASPagerNode;
12+
13+
@protocol ASPagerNodeDataSource <ASCollectionDataSource>
14+
15+
// This method replaces -collectionView:numberOfItemsInSection:
16+
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode;
17+
18+
// This method replaces -collectionView:nodeForItemAtIndexPath:
19+
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
20+
21+
@end
1222

1323
@interface ASPagerNode : ASCollectionNode
1424

@@ -32,12 +42,3 @@
3242

3343
@end
3444

35-
@protocol ASPagerNodeDataSource <NSObject>
36-
37-
// This method replaces -collectionView:numberOfItemsInSection:
38-
- (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode;
39-
40-
// This method replaces -collectionView:nodeForItemAtIndexPath:
41-
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
42-
43-
@end

AsyncDisplayKit/ASPagerNode.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#import <AsyncDisplayKit/AsyncDisplayKit.h>
1313

14-
@interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout> {
14+
@interface ASPagerNode () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout, ASDelegateProxyInterceptor> {
1515
UICollectionViewFlowLayout *_flowLayout;
1616
ASPagerNodeProxy *_proxy;
1717
id <ASPagerNodeDataSource> _pagerDataSource;
@@ -20,6 +20,7 @@ @interface ASPagerNode () <ASCollectionViewDataSource, ASCollectionViewDelegateF
2020
@end
2121

2222
@implementation ASPagerNode
23+
@dynamic delegate;
2324

2425
- (instancetype)init
2526
{
@@ -50,10 +51,15 @@ - (void)setDataSource:(id <ASPagerNodeDataSource>)pagerDataSource
5051
if (pagerDataSource != _pagerDataSource) {
5152
_pagerDataSource = pagerDataSource;
5253
_proxy = pagerDataSource ? [[ASPagerNodeProxy alloc] initWithTarget:pagerDataSource interceptor:self] : nil;
53-
super.dataSource = _proxy;
54+
super.dataSource = (id <ASCollectionDataSource>)_proxy;
5455
}
5556
}
5657

58+
- (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy
59+
{
60+
[self setDataSource:nil];
61+
}
62+
5763
- (id <ASPagerNodeDataSource>)dataSource
5864
{
5965
return _pagerDataSource;

AsyncDisplayKit/ASTableNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
*/
1515
@interface ASTableNode : ASDisplayNode
1616

17-
- (instancetype)initWithStyle:(UITableViewStyle)style NS_DESIGNATED_INITIALIZER;
17+
- (instancetype)init; // UITableViewStylePlain
18+
- (instancetype)initWithStyle:(UITableViewStyle)style;
1819

1920
@property (nonatomic, readonly) ASTableView *view;
2021

AsyncDisplayKit/ASTableNode.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,31 @@ @interface ASTableNode ()
2121
@end
2222

2323
@interface ASTableView ()
24-
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
24+
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass;
2525
@end
2626

2727
@implementation ASTableNode
2828

29-
- (instancetype)initWithStyle:(UITableViewStyle)style
29+
- (instancetype)_initWithStyle:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass
3030
{
31-
if (self = [super initWithViewBlock:^UIView *{ return [[ASTableView alloc] _initWithFrame:CGRectZero style:style]; }]) {
31+
if (self = [super initWithViewBlock:^UIView *{ return [[ASTableView alloc] _initWithFrame:CGRectZero
32+
style:style
33+
dataControllerClass:dataControllerClass]; }]) {
3234
return self;
3335
}
3436
return nil;
3537
}
3638

39+
- (instancetype)initWithStyle:(UITableViewStyle)style
40+
{
41+
return [self _initWithStyle:style dataControllerClass:nil];
42+
}
43+
44+
- (instancetype)init
45+
{
46+
return [self _initWithStyle:UITableViewStylePlain dataControllerClass:nil];
47+
}
48+
3749
- (void)didLoad
3850
{
3951
[super didLoad];

AsyncDisplayKit/ASTableView.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
*/
88

99
#import <UIKit/UIKit.h>
10-
1110
#import <AsyncDisplayKit/ASRangeController.h>
1211
#import <AsyncDisplayKit/ASTableViewProtocols.h>
1312
#import <AsyncDisplayKit/ASBaseDefines.h>
1413
#import <AsyncDisplayKit/ASBatchContext.h>
1514

16-
1715
@class ASCellNode;
18-
@protocol ASTableViewDataSource;
19-
@protocol ASTableViewDelegate;
20-
16+
@protocol ASTableDataSource;
17+
@protocol ASTableDelegate;
2118

2219
/**
2320
* Node-based table view.
@@ -27,8 +24,8 @@
2724
*/
2825
@interface ASTableView : UITableView
2926

30-
@property (nonatomic, weak) id<ASTableViewDelegate> asyncDelegate; // must not be nil
31-
@property (nonatomic, weak) id<ASTableViewDataSource> asyncDataSource;
27+
@property (nonatomic, weak) id<ASTableDelegate> asyncDelegate;
28+
@property (nonatomic, weak) id<ASTableDataSource> asyncDataSource;
3229

3330
/**
3431
* Initializer.
@@ -280,9 +277,8 @@
280277
/**
281278
* This is a node-based UITableViewDataSource.
282279
*/
283-
@protocol ASTableDataSource <ASTableViewDataSource>
284-
@end
285-
@protocol ASTableViewDataSource <ASCommonTableViewDataSource, NSObject>
280+
#define ASTableViewDataSource ASTableDataSource
281+
@protocol ASTableDataSource <ASCommonTableViewDataSource, NSObject>
286282

287283
/**
288284
* Similar to -tableView:cellForRowAtIndexPath:.
@@ -326,9 +322,8 @@
326322
* Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are
327323
* responsible for deciding their preferred onscreen height in -calculateSizeThatFits:.
328324
*/
329-
@protocol ASTableDelegate <ASTableViewDelegate>
330-
@end
331-
@protocol ASTableViewDelegate <ASCommonTableViewDelegate, NSObject>
325+
#define ASTableViewDelegate ASTableDelegate
326+
@protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject>
332327

333328
@optional
334329

AsyncDisplayKit/ASTableView.mm

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#import "ASLayoutController.h"
2222
#import "ASRangeController.h"
2323

24+
#import <CoreFoundation/CoreFoundation.h>
25+
2426
static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
2527

2628
//#define LOG(...) NSLog(__VA_ARGS__)
@@ -80,6 +82,10 @@ - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
8082
#pragma mark -
8183
#pragma mark ASTableView
8284

85+
@interface ASTableNode ()
86+
- (instancetype)_initWithStyle:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass;
87+
@end
88+
8389
@interface ASTableView () <ASRangeControllerDataSource, ASRangeControllerDelegate, ASDataControllerSource, _ASTableViewCellDelegate, ASCellNodeLayoutDelegate, ASDelegateProxyInterceptor> {
8490
ASTableViewProxy *_proxyDataSource;
8591
ASTableViewProxy *_proxyDelegate;
@@ -168,17 +174,21 @@ - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style asyncD
168174

169175
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass asyncDataFetching:(BOOL)asyncDataFetchingEnabled
170176
{
171-
ASTableNode *tableNode = [[ASTableNode alloc] initWithStyle:style];
172-
tableNode.frame = frame;
173-
return tableNode.view;
177+
// ASTableNode *tableNode = [[ASTableNode alloc] _initWithStyle:style dataControllerClass:dataControllerClass];
178+
// tableNode.frame = frame;
179+
// return tableNode.view;
180+
return [self _initWithFrame:frame style:style dataControllerClass:dataControllerClass];
174181
}
175182

176-
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style
183+
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass
177184
{
178185
if (!(self = [super initWithFrame:frame style:style]))
179186
return nil;
180187

181-
[self configureWithDataControllerClass:[self.class dataControllerClass] asyncDataFetching:NO];
188+
if (!dataControllerClass) {
189+
dataControllerClass = [self.class dataControllerClass];
190+
}
191+
[self configureWithDataControllerClass:dataControllerClass asyncDataFetching:NO];
182192

183193
return self;
184194
}

AsyncDisplayKit/Details/ASCollectionViewFlowLayoutInspector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import <AsyncDisplayKit/ASDimension.h>
1212

1313
@class ASCollectionView;
14-
@protocol ASCollectionViewDelegate;
14+
@protocol ASCollectionDelegate;
1515

1616
@protocol ASCollectionViewLayoutInspecting <NSObject>
1717

@@ -42,7 +42,7 @@
4242
*
4343
* @discussion A great time to update perform selector caches!
4444
*/
45-
- (void)didChangeCollectionViewDelegate:(id<ASCollectionViewDelegate>)delegate;
45+
- (void)didChangeCollectionViewDelegate:(id<ASCollectionDelegate>)delegate;
4646

4747
@end
4848

AsyncDisplayKit/Details/ASCollectionViewFlowLayoutInspector.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (instancetype)initWithCollectionView:(ASCollectionView *)collectionView flowLa
3636
return self;
3737
}
3838

39-
- (void)didChangeCollectionViewDelegate:(id<ASCollectionViewDelegate>)delegate;
39+
- (void)didChangeCollectionViewDelegate:(id<ASCollectionDelegate>)delegate;
4040
{
4141
if (delegate == nil) {
4242
_delegateImplementsReferenceSizeForHeader = NO;

0 commit comments

Comments
 (0)