Skip to content

Commit 003551e

Browse files
committed
expose FUIIndexArray's indexes in data sources
1 parent f6518d0 commit 003551e

6 files changed

+50
-1
lines changed

FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ didFailLoadAtIndex:(NSUInteger)index
5757
*/
5858
@interface FUIIndexCollectionViewDataSource : NSObject <UICollectionViewDataSource>
5959

60+
/**
61+
* The delegate that should receive updates from this data source. Implement this delegate
62+
* to handle load errors and successes.
63+
*/
6064
@property (nonatomic, readwrite, weak, nullable) id<FUIIndexCollectionViewDataSourceDelegate> delegate;
6165

66+
/**
67+
* The indexes that have finished loading in the data source. Returns an empty array if no indexes
68+
* have loaded.
69+
*/
70+
@property (nonatomic, readonly, copy) NSArray<FIRDataSnapshot *> *indexes;
71+
6272
- (instancetype)init NS_UNAVAILABLE;
6373

6474
/**

FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
5050
return self;
5151
}
5252

53+
- (NSArray<FIRDataSnapshot *> *)indexes {
54+
return self.array.indexes;
55+
}
56+
5357
#pragma mark - FUIIndexArrayDelegate
5458

5559
- (void)array:(FUIIndexArray *)array

FirebaseDatabaseUI/FUIIndexTableViewDataSource.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ didFailLoadAtIndex:(NSUInteger)index
5858
@interface FUIIndexTableViewDataSource : NSObject <UITableViewDataSource>
5959

6060
/**
61-
* The delegate that will receive events from this data source.
61+
* The delegate that should receive updates from this data source. Implement this delegate
62+
* to handle load errors and successes.
6263
*/
6364
@property (nonatomic, readwrite, weak, nullable) id<FUIIndexTableViewDataSourceDelegate> delegate;
6465

66+
/**
67+
* The indexes that have finished loading in the data source. Returns an empty array if no indexes
68+
* have loaded.
69+
*/
70+
@property (nonatomic, readonly, copy) NSArray<FIRDataSnapshot *> *indexes;
71+
6572
- (instancetype)init NS_UNAVAILABLE;
6673

6774
/**

FirebaseDatabaseUI/FUIIndexTableViewDataSource.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
5858
return self;
5959
}
6060

61+
- (NSArray<FIRDataSnapshot *> *)indexes {
62+
return self.array.indexes;
63+
}
64+
6165
#pragma mark - FUIIndexArrayDelegate
6266

6367
- (void)array:(FUIIndexArray *)array

FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ - (void)tearDown {
9393
[super tearDown];
9494
}
9595

96+
- (void)testItReturnsItsArraysIndexes {
97+
NSArray *expectedIndexes = @[
98+
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
99+
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
100+
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
101+
];
102+
103+
NSArray *indexes = self.dataSource.indexes;
104+
105+
XCTAssert([indexes isEqual:expectedIndexes], @"expected data source's indexes to equal its array's indexes");
106+
}
107+
96108
- (void)testItPopulatesCells {
97109
UICollectionViewCell *cell = [self.dataSource collectionView:self.collectionView
98110
cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];

FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ - (void)tearDown {
8888
[super tearDown];
8989
}
9090

91+
- (void)testItReturnsItsArraysIndexes {
92+
NSArray *expectedIndexes = @[
93+
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
94+
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
95+
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
96+
];
97+
98+
NSArray *indexes = self.dataSource.indexes;
99+
100+
XCTAssert([indexes isEqual:expectedIndexes], @"expected data source's indexes to equal its array's indexes");
101+
}
102+
91103
- (void)testItPopulatesCells {
92104
UITableViewCell *cell = [self.dataSource tableView:self.tableView
93105
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

0 commit comments

Comments
 (0)