Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FirebaseDatabaseUI/FUIIndexArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
@optional

/**
* Delegate method called when the database reference at an index has
* Delegate method called when the database reference at an index has
* finished loading its contents.
* @param array The array containing the reference.
* @param ref The reference that was loaded.
Expand Down
8 changes: 8 additions & 0 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ didFailLoadAtIndex:(NSUInteger)index
NSIndexPath *indexPath,
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;

/**
* Returns the snapshot at the given index, if it has loaded.
* Raises a fatal error if the index is out of bounds.
* @param index The index of the requested snapshot.
* @return A snapshot, or nil if one has not yet been loaded.
*/
- (nullable FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index;

@end

@interface UICollectionView (FUIIndexCollectionViewDataSource)
Expand Down
4 changes: 4 additions & 0 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
return self.array.indexes;
}

- (FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index {
return [self.array objectAtIndex:index];
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
Expand Down
8 changes: 8 additions & 0 deletions FirebaseDatabaseUI/FUIIndexTableViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ didFailLoadAtIndex:(NSUInteger)index
NSIndexPath *indexPath,
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;

/**
* Returns the snapshot at the given index, if it has loaded.
* Raises a fatal error if the index is out of bounds.
* @param index The index of the requested snapshot.
* @return A snapshot, or nil if one has not yet been loaded.
*/
- (nullable FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index;

@end

@interface UITableView (FUIIndexTableViewDataSource)
Expand Down
4 changes: 4 additions & 0 deletions FirebaseDatabaseUI/FUIIndexTableViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
return self.array.indexes;
}

- (FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index {
return [self.array objectAtIndex:index];
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,10 @@ - (void)testItUpdatesOnMove {
XCTAssertEqualObjects(cell.accessibilityValue, @"3");
}

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

@end
6 changes: 6 additions & 0 deletions FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,10 @@ - (void)testItUpdatesOnMove {
XCTAssertEqualObjects(cell.accessibilityValue, @"3");
}

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

@end