Skip to content

Commit a3a3a6c

Browse files
committed
refactor table view data source
1 parent 050bf12 commit a3a3a6c

File tree

6 files changed

+65
-592
lines changed

6 files changed

+65
-592
lines changed

FirebaseDatabaseUI/FirebaseCollectionViewDataSource.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,28 @@ NS_ASSUME_NONNULL_BEGIN
5858
* provided by the datasource.
5959
*/
6060
@property(strong, nonatomic, readonly) UICollectionViewCell *(^populateCellAtIndexPath)
61-
(NSIndexPath *indexPath, UICollectionView *collectionView, FIRDataSnapshot *object);
61+
(UICollectionView *collectionView, NSIndexPath *indexPath, FIRDataSnapshot *object);
6262

6363
/**
6464
* Initialize an instance of FirebaseCollectionViewDataSource that populates
65-
* UICollectionViewCells
66-
* with FIRDataSnapshots.
67-
* @param query A Firebase query to bind the datasource to
68-
* @param collectionView An instance of a UICollectionView to bind to
65+
* UICollectionViewCells with FIRDataSnapshots.
66+
* @param query A Firebase query to bind the data source to.
67+
* @param collectionView An instance of a UICollectionView to bind to. This view
68+
* is not retained by its data source.
69+
* @param populateCell A closure used by the data source to create the cells that
70+
* are displayed in the collection view. This closure is retained by the data
71+
* source, so if you capture self in the closure and also claim ownership of the
72+
* data source, be sure to avoid retain cycles by capturing a weak reference to self.
6973
* @return An instance of FirebaseCollectionViewDataSource that populates
70-
* UICollectionViewCells with
71-
* FIRDataSnapshots
74+
* UICollectionViewCells with FIRDataSnapshots.
7275
*/
7376
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
7477
view:(UICollectionView *)collectionView
75-
populateCell:(UICollectionViewCell * (^)(NSIndexPath *indexPath,
76-
UICollectionView *collectionView,
77-
FIRDataSnapshot *object))populateCell;
78+
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
79+
NSIndexPath *indexPath,
80+
FIRDataSnapshot *object))populateCell NS_DESIGNATED_INITIALIZER;
81+
82+
- (instancetype)initWithArray:(FirebaseArray *)array NS_UNAVAILABLE;
7883

7984
@end
8085

FirebaseDatabaseUI/FirebaseCollectionViewDataSource.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ @implementation FirebaseCollectionViewDataSource
2828

2929
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
3030
view:(UICollectionView *)collectionView
31-
populateCell:(UICollectionViewCell *(^)(NSIndexPath *,
32-
UICollectionView *,
31+
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
32+
NSIndexPath *,
3333
FIRDataSnapshot *))populateCell {
3434
FirebaseArray *array = [[FirebaseArray alloc] initWithQuery:query];
3535
self = [super initWithArray:array];
@@ -69,7 +69,7 @@ - (nonnull UICollectionViewCell *)collectionView:(nonnull UICollectionView *)col
6969
cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
7070
FIRDataSnapshot *snap = [self.items objectAtIndex:indexPath.row];
7171

72-
UICollectionViewCell *cell = self.populateCellAtIndexPath(indexPath, collectionView, snap);
72+
UICollectionViewCell *cell = self.populateCellAtIndexPath(collectionView, indexPath, snap);
7373

7474
return cell;
7575
}

0 commit comments

Comments
 (0)