Skip to content

Commit ae71df9

Browse files
committed
Add real docs
1 parent fe5e68c commit ae71df9

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ visit the [main README][main-readme].
2020

2121
## Kotlin Extensions
2222

23+
The following Firebase SDKs for Android have Kotlin extension libraries
24+
that allow you to write more idiomatic Kotlin code when using Firebase
25+
in your app:
2326

27+
* [`firebase-firestore`](./ktx/firestore.md)
2428

2529
[android-setup]: https://firebase.google.com/docs/android/setup
2630
[main-readme]: https://github.com/firebase/firebase-android-sdk/blob/master/README.md

docs/ktx/firestore.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
11
# Firestore Kotlin Extensions
22

3+
## Getting Started
4+
5+
To use the Cloud Firestore Android SDK with Kotlin Extenstions, add the following
6+
to your app's `build.gradle` file:
7+
8+
```groovy
9+
// This library transitively includes the Firestore Android SDK
10+
implementation 'com.google.firebase:firebase-firestore-ktx:18.1.0
11+
```
12+
13+
## Features
14+
15+
### Convert a DocumentSnapshot field to a POJO
16+
17+
**Kotlin**
18+
```kotlin
19+
val snapshot: DocumentSnapshot = ...
20+
val myObject = snapshot.get("fieldPath", MyClass::class.java)
21+
```
22+
23+
**Kotlin + KTX**
24+
```kotlin
25+
val snapshot: DocumentSnapshot = ...
26+
val myObject = snapshot.get<MyClass>("fieldPath")
27+
```
28+
29+
### Get an instance of FirebaseFirestore
30+
31+
**Kotlin**
32+
```kotlin
33+
val firestore = FirebaseFirestore.getInstance()
334
```
4-
// TODO: Finish this page
35+
36+
**Kotlin + KTX**
37+
```kotlin
38+
val firestore = Firebase.firestore
39+
```
40+
41+
### Convert a DocumentSnapshot to a POJO
42+
43+
**Kotlin**
44+
```kotlin
45+
val snapshot: DocumentSnapshot = ...
46+
val myObject = snapshot.toObject(MyClass::class.java)
47+
```
48+
49+
**Kotlin + KTX**
50+
```kotlin
51+
val snapshot: DocumentSnapshot = ...
52+
val myObject = snapshot.toObject<MyClass>()
53+
```
54+
55+
### Convert a QuerySnapshot to a list of POJOs
56+
57+
**Kotlin**
58+
```kotlin
59+
val snapshot: QuerySnapshot = ...
60+
val objectList = snapshot.toObjects(MyClass::class.java)
61+
```
62+
63+
**Kotlin + KTX**
64+
```kotlin
65+
val snapshot: QuerySnapshot = ...
66+
val objectList = snapshot.toObjects<MyClass>()
567
```

0 commit comments

Comments
 (0)