Skip to content

Commit 5098dda

Browse files
committed
Added docs to all headers. Broke FirebaseArrayDelegate into it's own protocol.
1 parent 6978c94 commit 5098dda

File tree

6 files changed

+221
-29
lines changed

6 files changed

+221
-29
lines changed

FirebaseUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/* End PBXAggregateTarget section */
2323

2424
/* Begin PBXBuildFile section */
25+
D8784C3D1B7186F40025587E /* FirebaseArrayDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = D8784C3C1B7186F40025587E /* FirebaseArrayDelegate.h */; };
2526
D8B6ACE51B58383C005CDDB2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8C579BB1B5837DF00899F86 /* UIKit.framework */; };
2627
D8B6ACE71B583877005CDDB2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8B6ACE61B583877005CDDB2 /* Foundation.framework */; };
2728
D8B6ACF31B583C41005CDDB2 /* FirebaseArray.m in Sources */ = {isa = PBXBuildFile; fileRef = D8B6ACEF1B583C41005CDDB2 /* FirebaseArray.m */; };
@@ -57,6 +58,7 @@
5758
/* End PBXCopyFilesBuildPhase section */
5859

5960
/* Begin PBXFileReference section */
61+
D8784C3C1B7186F40025587E /* FirebaseArrayDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FirebaseArrayDelegate.h; sourceTree = "<group>"; };
6062
D8B6ACE61B583877005CDDB2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
6163
D8B6ACEB1B583C33005CDDB2 /* FirebaseUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FirebaseUI.h; path = API/FirebaseUI.h; sourceTree = "<group>"; };
6264
D8B6ACEC1B583C33005CDDB2 /* FirebaseArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FirebaseArray.h; path = API/FirebaseArray.h; sourceTree = "<group>"; };
@@ -111,6 +113,7 @@
111113
D8B6ACEC1B583C33005CDDB2 /* FirebaseArray.h */,
112114
D8B6ACED1B583C33005CDDB2 /* FirebaseDataSource.h */,
113115
D8B6ACEE1B583C33005CDDB2 /* FirebaseTableViewDataSource.h */,
116+
D8784C3C1B7186F40025587E /* FirebaseArrayDelegate.h */,
114117
);
115118
name = API;
116119
sourceTree = "<group>";
@@ -158,6 +161,7 @@
158161
isa = PBXHeadersBuildPhase;
159162
buildActionMask = 2147483647;
160163
files = (
164+
D8784C3D1B7186F40025587E /* FirebaseArrayDelegate.h in Headers */,
161165
D8B6ACF81B583D3E005CDDB2 /* FirebaseUI.h in Headers */,
162166
D8B6ACFA1B583D3E005CDDB2 /* FirebaseTableViewDataSource.h in Headers */,
163167
D8B6ACF91B583D3E005CDDB2 /* FirebaseDataSource.h in Headers */,

FirebaseUI/API/FirebaseArray.h

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,77 @@
2828

2929
#import <Foundation/Foundation.h>
3030

31+
#import <FirebaseUI/FirebaseArrayDelegate.h>
32+
3133
@class FQuery;
3234
@class Firebase;
3335

34-
@protocol FirebaseArrayDelegate;
35-
3636
@interface FirebaseArray : NSObject
3737

38+
/**
39+
* The delegate object that array changes are surfaced to, which conforms to the [FirebaseArrayDelegate Protocol](FirebaseArrayDelegate).
40+
*/
3841
@property (weak, nonatomic) id<FirebaseArrayDelegate> delegate;
3942

43+
/**
44+
* The query on a Firebase reference that provides data to populate the instance of FirebaseArray.
45+
*/
4046
@property (strong, nonatomic) FQuery *query;
47+
48+
/**
49+
* The delegate object that array changes are surfaced to.
50+
*/
4151
@property (strong, nonatomic) NSMutableArray *snapshots;
4252

4353
#pragma mark -
4454
#pragma mark Initializer methods
4555

56+
/**
57+
* Intitalizes FirebaseArray with a standard Firebase reference.
58+
* @param ref The Firebase reference which provides data to FirebaseArray
59+
* @return The instance of FirebaseArray
60+
*/
4661
- (instancetype)initWithRef:(Firebase *)ref;
62+
63+
/**
64+
* Intitalizes FirebaseArray with a Firebase query (FQuery).
65+
* @param query A query on a Firebase reference which provides filtered data to FirebaseArray
66+
* @return The instance of FirebaseArray
67+
*/
4768
- (instancetype)initWithQuery:(FQuery *)query;
4869

4970
#pragma mark -
5071
#pragma mark Public API methods
5172

73+
/**
74+
* Returns the count of objects in the FirebaseArray.
75+
* @return The count of objects in the FirebaseArray
76+
*/
5277
- (NSUInteger)count;
78+
79+
/**
80+
* Returns an object at a specific index in the FirebaseArray.
81+
* @param index The index of the item to retrieve
82+
* @return The object at the given index
83+
*/
5384
- (id)objectAtIndex:(NSUInteger)index;
85+
86+
/**
87+
* Returns a Firebase reference for an object at a specific index in the FirebaseArray.
88+
* @param index The index of the item to retrieve a reference for
89+
* @return A Firebase reference for the object at the given index
90+
*/
5491
- (Firebase *)refForIndex:(NSUInteger)index;
5592

5693
#pragma mark -
5794
#pragma mark Private API methods
5895

96+
/**
97+
* Returns an index for a given object's key (that matches the object's key in the corresponding Firebase reference).
98+
* @param key The key of the desired object
99+
* @return The index of the object for which the key matches or -1 if the key is null
100+
* @exception FirebaseArrayKeyNotFoundException Thrown when the desired key is not in the FirebaseArray, likely indicating that the FirebaseArray is no longer being properly synchronized with the Firebase database.
101+
*/
59102
- (NSUInteger)indexForKey:(NSString *)key;
60103

61104
@end
62-
63-
@protocol FirebaseArrayDelegate <NSObject>
64-
65-
@optional
66-
- (void) childAdded:(id)obj atIndex:(NSUInteger)index;
67-
- (void) childChanged:(id)obj atIndex:(NSUInteger)index;
68-
- (void) childRemoved:(id)obj atIndex:(NSUInteger)index;
69-
- (void) childMoved:(id)obj fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;
70-
71-
@end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Firebase UI Bindings iOS Library
3+
*
4+
* Copyright © 2015 Firebase - All Rights Reserved
5+
* https://www.firebase.com
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice, this
11+
* list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binaryform must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY FIREBASE AS IS AND ANY EXPRESS OR
18+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20+
* EVENT SHALL FIREBASE BE LIABLE FOR ANY DIRECT,
21+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25+
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26+
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
/**
30+
* A protocol to allow instances of FirebaseArray to raise events through a delegate. Raises all Firebase events except FEventTypeValue.
31+
*/
32+
33+
@protocol FirebaseArrayDelegate <NSObject>
34+
35+
@optional
36+
37+
/**
38+
* Delegate method which is called whenever an object is added to a FirebaseArray. On a FirebaseArray synchronized to a Firebase reference, this corresponds to an [FEventTypeChildAdded](https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-event-types) event being raised.
39+
* @param object The object added to the FirebaseArray
40+
* @param index The index the child was added at
41+
*/
42+
- (void) childAdded:(id)object atIndex:(NSUInteger)index;
43+
44+
/**
45+
* Delegate method which is called whenever an object is chinged in a FirebaseArray. On a FirebaseArray synchronized to a Firebase reference, this corresponds to an [FEventTypeChildChanged](https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-event-types) event being raised.
46+
* @param object The object that changed in the FirebaseArray
47+
* @param index The index the child was changed at
48+
*/
49+
- (void) childChanged:(id)object atIndex:(NSUInteger)index;
50+
51+
/**
52+
* Delegate method which is called whenever an object is removed from a FirebaseArray. On a FirebaseArray synchronized to a Firebase reference, this corresponds to an [FEventTypeChildRemoved](https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-event-types) event being raised.
53+
* @param object The object removed from the FirebaseArray
54+
* @param index The index the child was removed at
55+
*/
56+
- (void) childRemoved:(id)object atIndex:(NSUInteger)index;
57+
58+
/**
59+
* Delegate method which is called whenever an object is moved within a FirebaseArray. On a FirebaseArray synchronized to a Firebase reference, this corresponds to an [FEventTypeChildMoved](https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-event-types) event being raised.
60+
* @param object The object that has moved locations in the FirebaseArray
61+
* @param fromIndex The index the child is being moved from
62+
* @param toIndex The index the child is being moved to
63+
*/
64+
- (void) childMoved:(id)object fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;
65+
66+
@end

FirebaseUI/API/FirebaseDataSource.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,36 @@
2828

2929
#import <Foundation/Foundation.h>
3030

31-
#import "FirebaseArray.h"
31+
#import <FirebaseUI/FirebaseArray.h>
3232

3333
@class Firebase;
3434

35-
@protocol FirebaseDataSource;
36-
35+
/**
36+
* A FirebaseDataSource is a generic superclass for all Firebase datasources, like FirebaseTableViewDataSource and FirebaseCollectionViewDataSource. It provides properties that all subclasses need as well as several methods that pass through to the instance of FirebaseArray.
37+
*/
3738
@interface FirebaseDataSource : NSObject <FirebaseArrayDelegate>
3839

40+
/**
41+
* The FirebaseArray which backs the instance of the datasource.
42+
*/
3943
@property (strong, nonatomic) FirebaseArray *array;
40-
@property (strong, nonatomic) Class modelClass;
41-
@property (strong, nonatomic) NSString *reuseIdentifier;
44+
4245

4346
- (instancetype)initWithArray:(FirebaseArray *)array;
4447

48+
/**
49+
* Pass through of [FirebaseArray count].
50+
*/
4551
- (NSUInteger)count;
52+
53+
/**
54+
* Pass through of [FirebaseArray objectAtIndex:].
55+
*/
4656
- (id)objectAtIndex:(NSUInteger)index;
57+
58+
/**
59+
* Pass through of [FirebaseArray refForIndex:].
60+
*/
4761
- (Firebase *)refForIndex:(NSUInteger)index;
4862

4963
@end

FirebaseUI/API/FirebaseTableViewDataSource.h

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,96 @@
2828

2929
#import <UIKit/UIKit.h>
3030

31-
#import "FirebaseDataSource.h"
31+
#import <FirebaseUI/FirebaseDataSource.h>
3232

3333
@interface FirebaseTableViewDataSource : FirebaseDataSource <UITableViewDataSource>
3434

35+
/**
36+
* The model class to coerce FDataSnapshots to (if desired). For instance, if the modelClass is set to [Message class], then objects of type Message will be returned instead of type FDataSnapshot.
37+
*/
38+
@property (strong, nonatomic) Class modelClass;
39+
40+
/**
41+
* The reuse identifier for cells in the UITableView.
42+
*/
43+
@property (strong, nonatomic) NSString *reuseIdentifier;
44+
45+
/**
46+
* The UITableView instance that operations (inserts, removals, moves, etc.) are performed against.
47+
*/
3548
@property (strong, nonatomic) UITableView *tableView;
36-
@property (strong, nonatomic) void(^populateCell)(id cell, id snap);
3749

50+
/**
51+
* The callback to populate a subclass of UITableViewCell with an object provided by the datasource.
52+
*/
53+
@property (strong, nonatomic) void(^populateCell)(id cell, id object);
54+
55+
/**
56+
* Initialize an instance of FirebaseTableViewDataSource that populates UITableViewCells with FDataSnapshots.
57+
* @param ref A Firebase reference to bind the datasource to
58+
* @param identifier A string to use as a CellReuseIdentifier
59+
* @param tableView An instance of a UITableView to bind to
60+
* @return An instance of FirebaseTableViewDataSource that populates UITableViewCells with FDataSnapshots
61+
*/
3862
- (instancetype)initWithRef:(Firebase *)ref reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
63+
64+
/**
65+
* Initialize an instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with FDataSnapshots.
66+
* @param ref A Firebase reference to bind the datasource to
67+
* @param cell A subclass of UITableViewCell that will
68+
* @param identifier A string to use as a CellReuseIdentifier
69+
* @param tableView An instance of a UITableView to bind to
70+
* @return An instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with FDataSnapshots
71+
*/
3972
- (instancetype)initWithRef:(Firebase *)ref cellClass:(Class)cell reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
40-
- (instancetype)initWithRef:(Firebase *)ref nibNamed:(NSString *)name reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
73+
74+
/**
75+
* Initialize an instance of FirebaseTableViewDataSource that populates a custom xib with FDataSnapshots.
76+
* @param ref A Firebase reference to bind the datasource to
77+
* @param nibName The name of a xib file to create the layout for a UITableViewCell
78+
* @param identifier A string to use as a CellReuseIdentifier
79+
* @param tableView An instance of a UITableView to bind to
80+
* @return An instance of FirebaseTableViewDataSource that populates a custom xib with FDataSnapshots
81+
*/
82+
- (instancetype)initWithRef:(Firebase *)ref nibNamed:(NSString *)nibName reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
83+
84+
/**
85+
* Initialize an instance of FirebaseTableViewDataSource that populates UITableViewCells with a custom model class.
86+
* @param ref A Firebase reference to bind the datasource to
87+
* @param model A custom class that FDataSnapshots are coerced to
88+
* @param identifier A string to use as a CellReuseIdentifier
89+
* @param tableView An instance of a UITableView to bind to
90+
* @return An instance of FirebaseTableViewDataSource that populates UITableViewCells with a custom model class
91+
*/
4192
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
93+
94+
/**
95+
* Initialize an instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with a custom model class.
96+
* @param ref A Firebase reference to bind the datasource to
97+
* @param model A custom class that FDataSnapshots are coerced to
98+
* @param cell A subclass of UITableViewCell that will
99+
* @param identifier A string to use as a CellReuseIdentifier
100+
* @param tableView An instance of a UITableView to bind to
101+
* @return An instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with a custom model class
102+
*/
42103
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model cellClass:(Class)cell reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
43-
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model nibNamed:(NSString *)name reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
44104

45-
- (void)populateCellWithBlock:(void(^)(id cell, id snap))callback;
105+
/**
106+
* Initialize an instance of FirebaseTableViewDataSource that populates a custom xib with a custom model class.
107+
* @param ref A Firebase reference to bind the datasource to
108+
* @param model A custom class that FDataSnapshots are coerced to
109+
* @param nibName The name of a xib file to create the layout for a UITableViewCell
110+
* @param identifier A string to use as a CellReuseIdentifier
111+
* @param tableView An instance of a UITableView to bind to
112+
* @return An instance of FirebaseTableViewDataSource that populates a custom xib with a custom model class
113+
*/
114+
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model nibNamed:(NSString *)nibName reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
115+
116+
/**
117+
* This method populates the fields of a UITableViewCell or subclass given a model object (or FDataSnapshot).
118+
* @param callback A block which returns an initialized UITableViewCell (or subclass) and the corresponding object to populate the cell with.
119+
*/
120+
- (void)populateCellWithBlock:(void(^)(id cell, id object))callback;
46121

47122
@end
48123

FirebaseUI/Implementation/FirebaseTableViewDataSource.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ - (instancetype)initWithRef:(Firebase *)ref cellClass:(Class)cell reuseIdentifie
4545
return [self initWithRef:ref modelClass:[FDataSnapshot class] cellClass:cell reuseIdentifier:identifier view:tableView];
4646
}
4747

48-
- (instancetype)initWithRef:(Firebase *)ref nibNamed:(NSString *)name reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
48+
- (instancetype)initWithRef:(Firebase *)ref nibNamed:(NSString *)nibName reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
4949
{
50-
return [self initWithRef:ref modelClass:[FDataSnapshot class] nibNamed:name reuseIdentifier:identifier view:tableView];
50+
return [self initWithRef:ref modelClass:[FDataSnapshot class] nibNamed:nibName reuseIdentifier:identifier view:tableView];
5151
}
5252

5353
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
@@ -63,7 +63,7 @@ - (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model cellClass:(C
6363
self.tableView = tableView;
6464
self.modelClass = model;
6565
self.reuseIdentifier = identifier;
66-
self.populateCell = ^(id cell, id snap) {};
66+
self.populateCell = ^(id cell, id object) {};
6767

6868
if (![self.tableView dequeueReusableCellWithIdentifier:self.reuseIdentifier]) {
6969
[self.tableView registerClass:cell forCellReuseIdentifier:self.reuseIdentifier];
@@ -72,18 +72,18 @@ - (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model cellClass:(C
7272
return self;
7373
}
7474

75-
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model nibNamed:(NSString *)name reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
75+
- (instancetype)initWithRef:(Firebase *)ref modelClass:(Class)model nibNamed:(NSString *)nibName reuseIdentifier:(NSString *)identifier view:(UITableView *)tableView;
7676
{
7777
FirebaseArray *array = [[FirebaseArray alloc] initWithRef:ref];
7878
self = [super initWithArray:array];
7979
if (self) {
8080
self.tableView = tableView;
8181
self.modelClass = model;
8282
self.reuseIdentifier = identifier;
83-
self.populateCell = ^(id cell, id snap) {};
83+
self.populateCell = ^(id cell, id object) {};
8484

8585
if (![self.tableView dequeueReusableCellWithIdentifier:self.reuseIdentifier]) {
86-
UINib *nib = [UINib nibWithNibName:name bundle:nil];
86+
UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
8787
[self.tableView registerNib:nib forCellReuseIdentifier:self.reuseIdentifier];
8888
}
8989
}
@@ -146,7 +146,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
146146
return [self.array count];
147147
}
148148

149-
- (void)populateCellWithBlock:(void(^)(id cell, id snap))callback;
149+
- (void)populateCellWithBlock:(void(^)(id cell, id object))callback;
150150
{
151151
self.populateCell = callback;
152152
}

0 commit comments

Comments
 (0)