Skip to content

Commit 35bfe1a

Browse files
committed
Please enter the commit message for your changes. Lines starting
1 parent c478ef0 commit 35bfe1a

File tree

2 files changed

+207
-42
lines changed

2 files changed

+207
-42
lines changed

FirebaseUI/API/FirebaseArray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
@class FQuery;
3434
@class Firebase;
35+
@class FDataSnapshot;
3536

3637
/**
3738
* FirebaseArray provides an array structure that is synchronized with a Firebase reference or query. It is useful for building custom data structures or sources, and provides the base for FirebaseDataSource.

README.md

Lines changed: 206 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@ We recommend using [CocoaPods](http://cocoapods.org/?q=firebaseui-ios), add
1010
the following to your `Podfile`:
1111

1212
```
13-
pod 'FirebaseUI', '>= 0.1.0'
13+
pod 'FirebaseUI', '~> 0.2'
14+
```
15+
16+
If you're including FirebaseUI in a Swift project, make sure you also have:
17+
18+
```
19+
platform :ios, '8.0'
20+
use_frameworks!
1421
```
1522

1623
Otherwise, you can download the latest version of the [FirebaseUI.framework from the releases
1724
page](https://github.com/firebase/FirebaseUI-iOS/releases) or include the FirebaseUI
1825
Xcode project from this repo in your project. You also need to [add the Firebase
1926
framework](https://www.firebase.com/docs/ios-quickstart.html?utm_source=firebaseui-ios) to your project.
2027

21-
### Using FirebaseUI with Swift
22-
23-
In order to use FirebaseUI in a Swift project, you'll also need to setup a bridging
24-
header, in addition to adding the Firebase and FirebaseUI frameworks
25-
to your project. To do that, [follow these instructions](https://www.firebase.com/docs/ios/guide/setup.html#section-swift), and then add the following line to your bridging header:
26-
27-
````objective-c
28-
#import <FirebaseUI/FirebaseUI.h>
29-
````
30-
3128
## Getting Started with Firebase
3229

3330
FirebaseUI requires Firebase in order to store location data. You can [sign up here for a free
@@ -41,16 +38,16 @@ This is a quickstart on how to use FirebaseUI's core features to speed up iOS de
4138

4239
FirebaseTableViewDataSource implements the UITableViewDataSource protocol to automatically use Firebase as a DataSource for your UITableView.
4340

44-
##### Objective-C
41+
#### Objective-C
4542
```objective-c
46-
MyViewController.h
43+
YourViewController.h
4744
...
48-
@property (strong, nonatomic) Firebase *ref;
45+
@property (strong, nonatomic) Firebase *firebaseRef;
4946
@property (strong, nonatomic) FirebaseTableViewDataSource *dataSource;
5047
```
5148

5249
```objective-c
53-
MyViewController.m
50+
YourViewController.m
5451
...
5552
self.firebaseRef = [[Firebase alloc] initWithUrl:@"https://<your-firebase-app>.firebaseio.com/"];
5653
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef reuseIdentifier:@"<your-reuse-identifier>" view:self.tableView];
@@ -63,29 +60,81 @@ self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef r
6360
[self.tableView setDataSource:self.dataSource];
6461
```
6562
66-
## Creating Custom TableViews with FirebaseTableViewDataSource
63+
#### Swift
64+
```swift
65+
YourViewController.swift
66+
...
67+
let firebaseRef = Firebase(url:"https://<your-firebase-app>.firebaseio.com/")
68+
let dataSource: FirebaseTableViewDataSource!
69+
...
70+
self.dataSource = FirebaseTableViewDataSource(ref: self.firebaseRef, reuseIdentifier: "<your-reuse-identifier>", view: self.tableView)
71+
72+
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
73+
let snap = obj as! FDataSnapshot
74+
75+
// Populate cell as you see fit, like as below
76+
cell.textLabel?.text = snap.key as String
77+
}
78+
79+
self.tableView.dataSource = self.dataSource
6780
68-
You can use FirebaseTableViewDataSource in several ways to create custom UITableViews. For more information on how to create custom UITableViews, check out the following tutorial on [TutsPlus](http://code.tutsplus.com/tutorials/ios-sdk-crafting-custom-uitableview-cells--mobile-15702).
81+
```
6982

70-
### Using the Default UITableViewCell Implementation
83+
### FirebaseCollectionViewDataSource
7184

72-
You can use the default UITableViewCell implementation to get up and running quickly. This allows for the `cell.textLabel` and the `cell.detailTextLabel` to be used directly out of the box.
85+
FirebaseCollectionViewDataSource implements the UICollectionViewDataSource protocol to automatically use Firebase as a DataSource for your UICollectionView.
7386

87+
#### Objective-C
7488
```objective-c
75-
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef reuseIdentifier:@"<your-reuse-identifier>" view:self.tableView];
89+
YourViewController.h
90+
...
91+
@property (strong, nonatomic) Firebase *firebaseRef;
92+
@property (strong, nonatomic) FirebaseCollectionViewDataSource *dataSource;
93+
```
7694

77-
[self.dataSource populateCellWithBlock:^(UITableViewCell *cell, FDataSnapshot *snap) {
95+
```objective-c
96+
YourViewController.m
97+
...
98+
self.firebaseRef = [[Firebase alloc] initWithUrl:@"https://<your-firebase-app>.firebaseio.com/"];
99+
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef reuseIdentifier:@"<your-reuse-identifier>" view:self.CollectionView];
100+
101+
[self.dataSource populateCellWithBlock:^(UICollectionViewCell *cell, FDataSnapshot *snap) {
78102
// Populate cell as you see fit, like as below
79-
cell.textLabel.text = snap.key;
103+
cell.backgroundColor = [UIColor blueColor];
80104
}];
81105

82-
[self.tableView setDataSource:self.dataSource];
106+
[self.collectionView setDataSource:self.dataSource];
83107
```
84108
85-
### Using Storyboards and Prototype Cells
109+
#### Swift
110+
```swift
111+
YourViewController.swift
112+
...
113+
let firebaseRef = Firebase(url: "https://<your-firebase-app>.firebaseio.com/")
114+
let dataSource: FirebaseCollectionViewDataSource!
115+
...
116+
self.dataSource = FirebaseCollectionViewDataSource(ref: self.firebaseRef, reuseIdentifier: "<your-reuse-identifier>", view: self.collectionView)
117+
118+
self.dataSource.populateCellWithBlock { (cell: UICollectionViewCell, obj: NSObject) -> Void in
119+
let snap = obj as! FDataSnapshot
120+
121+
// Populate cell as you see fit, like as below
122+
cell.backgroundColor = UIColor.blueColor()
123+
}
124+
125+
self.collectionView.dataSource = self.dataSource
126+
127+
```
86128

87-
Create a storyboard that has either a UITableViewController or a UIViewController with a UITableView. Drag a prototype cell onto the UITableView and give it a custom ReuseIdentifier. Drag and other properties onto the cell and associate them with properties of a UITableViewCell subclass.
129+
## Customizing your UITableView or UICollectionView
88130

131+
You can use `FirebaseTableViewDataSource` or `FirebaseCollectionViewDataSource` in several ways to create custom UITableViews or UICollectionViews. For more information on how to create custom UITableViews, check out the following tutorial on [TutsPlus](http://code.tutsplus.com/tutorials/ios-sdk-crafting-custom-uitableview-cells--mobile-15702). For more information on how to create custom UICollectionViews, particularly how to implement a UICollectionViewLayout, check out the following tutorial on Ray Wenderlich in [Objective-C](http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12) and [Swift](http://www.raywenderlich.com/78550/beginning-ios-collection-views-swift-part-1).
132+
133+
### Using the Default UI*ViewCell Implementation
134+
135+
You can use the default `UITableViewCell` or `UICollectionViewCell` implementations to get up and running quickly. For `UITableViewCell`s, this allows for the `cell.textLabel` and the `cell.detailTextLabel` to be used directly out of the box. For `UICollectionViewCell`s, you will have to add subviews to the contentView in order for it to be useful.
136+
137+
#### Objective-C UITableView and UICollectionView with Default UI*ViewCell
89138
```objective-c
90139
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef reuseIdentifier:@"<your-reuse-identifier>" view:self.tableView];
91140

@@ -97,57 +146,171 @@ self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef r
97146
[self.tableView setDataSource:self.dataSource];
98147
```
99148
100-
### Using a Custom Subclass of UITableViewCell
149+
```objective-c
150+
self.dataSource = [[FirebaseCollectioneViewDataSource alloc] initWithRef:firebaseRef reuseIdentifier:@"<your-reuse-identifier>" view:self.CollectionView];
151+
152+
[self.dataSource populateCellWithBlock:^(UICollectionViewCell *cell, FDataSnapshot *snap) {
153+
// Populate cell as you see fit by adding subviews as appropriate
154+
[cell.contentView addSubview:customView];
155+
}];
156+
157+
[self.collectionView setDataSource:self.dataSource];
158+
```
159+
160+
#### Swift UITableView and UICollectionView with Default UI*ViewCell
161+
```swift
162+
self.dataSource = FirebaseTableViewDataSource(ref: firebaseRef reuseIdentifier: @"<your-reuse-identifier>" view: self.tableView)
163+
164+
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
165+
// Populate cell as you see fit, like as below
166+
cell.textLabel.text = snap.key;
167+
}
168+
169+
self.tableView.dataSource = self.dataSource;
170+
```
171+
172+
```swift
173+
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef reuseIdentifier: @"<your-reuse-identifier>" view: self.collectionView)
174+
175+
self.dataSource.populateCellWithBlock { (cell: UICollectionViewCell, obj: NSObject) -> Void in
176+
// Populate cell as you see fit by adding subviews as appropriate
177+
cell.contentView.addSubview(customView)
178+
}
179+
180+
self.collectionView.dataSource = self.dataSource;
181+
```
182+
183+
### Using Storyboards and Prototype Cells
184+
185+
Create a storyboard that has either a `UITableViewController`, `UICollectionViewController` or a `UIViewController` with a `UITableView` or `UICollectionView`. Drag a prototype cell onto the `UITableView` or `UICollectionView` and give it a custom reuse identifier which matches the reuse identifier being used when instantiating the `Firebase*ViewDataSource`. Drag and other properties onto the cell and associate them with properties of a `UITableViewCell` or `UICollectionViewCell` subclass. Code samples are similar to the above.
101186

102-
Create a custom subclass of UITableViewCell, with or without the XIB file. Make sure to instantiate `-initWithStyle: reuseIdentifier:` to instantiate the Cells. You can then hook the custom class up to the implementation of FirebaseTableViewDataSource.
187+
### Using a Custom Subclass of UI*ViewCell
103188

189+
Create a custom subclass of `UITableViewCell` or `UICollectionViewCell`, with or without the XIB file. Make sure to instantiate `-initWithStyle: reuseIdentifier:` to instantiate a `UITableViewCell` or `-initWithFrame:` to instantiate a `UICollectionViewCell`. You can then hook the custom class up to the implementation of `FirebaseTableViewDataSource`.
190+
191+
#### Objective-C UITableView and UICollectionView with Custom Subclasses of UI*ViewCell
104192
```objective-c
105-
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef cellClass:[YourCustomCell class] reuseIdentifier:@"<your-reuse-identifier>" view:self.tableView];
193+
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef cellClass:[YourCustomClass class] reuseIdentifier:@"<your-reuse-identifier>" view:self.tableView];
106194

107-
[self.dataSource populateCellWithBlock:^(YourCustomCell *cell, FDataSnapshot *snap) {
108-
// Populate your custom cell as you see fit, like as below
109-
cell.customLabel.text = snap.key;
195+
[self.dataSource populateCellWithBlock:^(YourCustomClass *cell, FDataSnapshot *snap) {
196+
// Populate custom cell as you see fit, like as below
197+
cell.yourCustomLabel.text = snap.key;
110198
}];
111199

112200
[self.tableView setDataSource:self.dataSource];
113201
```
114202
203+
```objective-c
204+
self.dataSource = [[FirebaseCollectioneViewDataSource alloc] initWithRef:firebaseRef cellClass:[YourCustomClass class] reuseIdentifier:@"<your-reuse-identifier>" view:self.CollectionView];
205+
206+
[self.dataSource populateCellWithBlock:^(YourCustomClass *cell, FDataSnapshot *snap) {
207+
// Populate cell as you see fit
208+
cell.customView = customView;
209+
}];
210+
211+
[self.collectionView setDataSource:self.dataSource];
212+
```
213+
214+
#### Swift UITableView and UICollectionView with Custom Subclasses of UI*ViewCell
215+
```swift
216+
self.dataSource = FirebaseTableViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self reuseIdentifier: @"<your-reuse-identifier>" view: self.tableView)
217+
218+
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
219+
// Populate cell as you see fit, like as below
220+
cell.yourCustomLabel.text = snap.key;
221+
}
222+
223+
self.tableView.dataSource = self.dataSource;
224+
```
225+
226+
```swift
227+
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self reuseIdentifier: @"<your-reuse-identifier>" view: self.collectionView)
228+
229+
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
230+
// Populate cell as you see fit
231+
cell.customView = customView;
232+
}
233+
234+
self.collectionView.dataSource = self.dataSource;
235+
```
236+
115237
### Using a Custom XIB
116238

117-
Create a custom XIB file and add it to the cell prototype. You can then use this like any other UITableViewCell, though with custom tags if desired.
239+
Create a custom XIB file and hook it up to the prototype cell. You can then use this like any other UITableViewCell, either using custom tags or by using the custom class associated with the XIB.
118240

241+
#### Objective-C UITableView and UICollectionView with Custom XIB
119242
```objective-c
120243
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef nibNamed:@"<your-xib>" reuseIdentifier:@"<your-reuse-identifier>" view:self.tableView];
121244

122245
[self.dataSource populateCellWithBlock:^(UITableViewCell *cell, FDataSnapshot *snap) {
123-
// Populate your cell as you see fit, like as below
124-
cell.textLabel.text = snap.key;
246+
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
247+
UILabel *yourCustomLabel = (UILabel *)[cell.contentView viewWithTag:<your-tag>];
248+
yourCustomLabel.text = snap.key
249+
}];
125250

126-
// Use tags to populate custom properties
127-
UILabel *myCustomLabel = (UILabel *)[cell.contentView viewWithTag:<your-tag>];
128-
myCustomLabel.text = snap.key
251+
[self.tableView setDataSource:self.dataSource];
252+
```
253+
254+
```objective-c
255+
self.dataSource = [[FirebaseCollectionViewDataSource alloc] initWithRef:firebaseRef nibNamed:@"<your-xib>" reuseIdentifier:@"<your-reuse-identifier>" view:self.collectionView];
256+
257+
[self.dataSource populateCellWithBlock:^(UICollectionViewCell *cell, FDataSnapshot *snap) {
258+
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
259+
UILabel *yourCustomLabel = (UILabel *)[cell.contentView viewWithTag:<your-tag>];
260+
yourCustomLabel.text = snap.key
129261
}];
130262
131263
[self.tableView setDataSource:self.dataSource];
132264
```
133265

266+
#### Swift UITableView and UICollectionView with Custom XIB
267+
```swift
268+
self.dataSource = FirebaseTableViewDataSource(ref: firebaseRef nibNamed: "<your-xib>" reuseIdentifier: @"<your-reuse-identifier>" view: self.tableView)
269+
270+
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
271+
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
272+
let yourCustomLabel: UILabel = cell.contentView.viewWithTag(<your-tag>) as! UILabel
273+
yourCustomLabel.text = snap.key
274+
}
275+
276+
self.tableView.dataSource = self.dataSource;
277+
```
278+
279+
```swift
280+
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self reuseIdentifier: @"<your-reuse-identifier>" view: self.collectionView)
281+
282+
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
283+
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
284+
let yourCustomLabel: UILabel = cell.contentView.viewWithTag(<your-tag>) as! UILabel
285+
yourCustomLabel.text = snap.key
286+
}
287+
288+
self.collectionView.dataSource = self.dataSource;
289+
```
290+
134291
## Understanding FirebaseUI's Internals
135292

136-
FirebaseUI has several building blocks that developers should understand before building additional functionality on top of FirebaseUI, including a synchronized array `FirebaseArray.*` and a generic data source superclass `FirebaseDataSource.*` from which FirebaseTableViewDataSource or other custom view classes subclass.
293+
FirebaseUI has several building blocks that developers should understand before building additional functionality on top of FirebaseUI, including a synchronized array `FirebaseArray` and a generic data source superclass `FirebaseDataSource` from which `FirebaseTableViewDataSource` and `FirebaseCollectionViewDataSource` or other custom view classes subclass.
137294

138295
### FirebaseArray and the FirebaseArrayDelegate Protocol
139296

140-
FirebaseArray is synchronized array connecting a Firebase Ref with an array. It surfaces Firebase events through the FirebaseArrayDelegate Protocol. It is generally recommended that developers not directly access FirebaseArray without routing it through a custom data source.
297+
`FirebaseArray` is synchronized array connecting a Firebase Ref with an array. It surfaces Firebase events through the FirebaseArrayDelegate Protocol. It is generally recommended that developers not directly access `FirebaseArray` without routing it through a custom data source, though if this is desired, check out `FirebaseDataSource` below.
141298

142-
##### Objective-C
299+
#### Objective-C
143300
```objective-c
144-
FirebaseArray *array = [[FirebaseArray alloc] initWithRef:@"https://<your-firebase-app>.firebaseio.com/"];
301+
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<your-firebase-app>.firebaseio.com/"];
302+
FirebaseArray *array = [[FirebaseArray alloc] initWithRef:firebaseRef];
303+
```
145304
305+
#### Swift
306+
```swift
307+
let firebaseRef = Firebase(url: "https://<your-firebase-app>.firebaseio.com/")
308+
let array = FirebaseArray(ref: firebaseRef)
146309
```
147310

148311
### FirebaseDataSource
149312

150-
FirebaseDataSource acts as a generic data source by providing common information, such as the count of objects in the data source, and by requiring subclasses to implement FirebaseArrayDelegate methods as appropriate to the view. This class should never be instantiated, but should be subclassed when creating a specific adapter for a View. [FirebaseTableViewDataSource](https://github.com/firebase/FirebaseUI-iOS/blob/master/FirebaseUI/Implementation/FirebaseTableViewDataSource.m) is an example of this.
313+
FirebaseDataSource acts as a generic data source by providing common information, such as the count of objects in the data source, and by requiring subclasses to implement FirebaseArrayDelegate methods as appropriate to the view. This class should never be instantiated, but should be subclassed when creating a specific adapter for a View. [FirebaseTableViewDataSource](https://github.com/firebase/FirebaseUI-iOS/blob/master/FirebaseUI/Implementation/FirebaseTableViewDataSource.m) and [FirebaseCollectionViewDataSource](https://github.com/firebase/FirebaseUI-iOS/blob/master/FirebaseUI/Implementation/FirebaseCollectionViewDataSource.m) are examples of this. FirebaseDataSource is essentially a wrapper around a FirebaseArray.
151314

152315
## Local Setup
153316

@@ -165,6 +328,7 @@ $ ./setup.sh
165328
- `git pull` to update the master branch
166329
- tag and push the tag for this release
167330
- `./build.sh` to build a binary
331+
- `./create-docs.sh` to generate docs
168332
- From your macbook that already has been granted permissions to FirebaseUI Cocoapods, do `pod trunk push`
169333
- Update [firebase-versions](https://github.com/firebase/firebase-clients/blob/master/versions/firebase-versions.json) with the changelog for this release.
170334

0 commit comments

Comments
 (0)