Skip to content

Commit 02e95ed

Browse files
committed
add snapshotAtIndex to indexed data sources
1 parent 347e817 commit 02e95ed

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

FirebaseDatabaseUI/FUIIndexArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
3333
@optional
3434

3535
/**
36-
* Delegate method called when the database reference at an index has
36+
* Delegate method called when the database reference at an index has
3737
* finished loading its contents.
3838
* @param array The array containing the reference.
3939
* @param ref The reference that was loaded.

FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ didFailLoadAtIndex:(NSUInteger)index
9191
NSIndexPath *indexPath,
9292
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;
9393

94+
/**
95+
* Returns the snapshot at the given index, if it has loaded.
96+
* Raises a fatal error if the index is out of bounds.
97+
* @param index The index of the requested snapshot.
98+
* @return A snapshot, or nil if one has not yet been loaded.
99+
*/
100+
- (nullable FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index;
101+
94102
@end
95103

96104
@interface UICollectionView (FUIIndexCollectionViewDataSource)

FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
5454
return self.array.indexes;
5555
}
5656

57+
- (FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index {
58+
return [self.array objectAtIndex:index];
59+
}
60+
5761
#pragma mark - FUIIndexArrayDelegate
5862

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

FirebaseDatabaseUI/FUIIndexTableViewDataSource.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ didFailLoadAtIndex:(NSUInteger)index
9191
NSIndexPath *indexPath,
9292
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;
9393

94+
/**
95+
* Returns the snapshot at the given index, if it has loaded.
96+
* Raises a fatal error if the index is out of bounds.
97+
* @param index The index of the requested snapshot.
98+
* @return A snapshot, or nil if one has not yet been loaded.
99+
*/
100+
- (nullable FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index;
101+
94102
@end
95103

96104
@interface UITableView (FUIIndexTableViewDataSource)

FirebaseDatabaseUI/FUIIndexTableViewDataSource.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
6262
return self.array.indexes;
6363
}
6464

65+
- (FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index {
66+
return [self.array objectAtIndex:index];
67+
}
68+
6569
#pragma mark - FUIIndexArrayDelegate
6670

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

FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,10 @@ - (void)testItUpdatesOnMove {
183183
XCTAssertEqualObjects(cell.accessibilityValue, @"3");
184184
}
185185

186+
- (void)testItReturnsSnapshotsFromItsIndexArray {
187+
FIRDataSnapshot *snap = [self.dataSource snapshotAtIndex:0];
188+
XCTAssertEqualObjects(snap.key, @"data", @"expected snap's key to equal 'data', got %@ instead", snap.key);
189+
XCTAssertEqualObjects(snap.value, @"1", @"expected snap's key to equal '1', got %@ instead", snap.value);
190+
}
191+
186192
@end

FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,10 @@ - (void)testItUpdatesOnMove {
178178
XCTAssertEqualObjects(cell.accessibilityValue, @"3");
179179
}
180180

181+
- (void)testItReturnsSnapshotsFromItsIndexArray {
182+
FIRDataSnapshot *snap = [self.dataSource snapshotAtIndex:0];
183+
XCTAssertEqualObjects(snap.key, @"data", @"expected snap's key to equal 'data', got %@ instead", snap.key);
184+
XCTAssertEqualObjects(snap.value, @"1", @"expected snap's key to equal '1', got %@ instead", snap.value);
185+
}
186+
181187
@end

0 commit comments

Comments
 (0)