File tree Expand file tree Collapse file tree 2 files changed +67
-1
lines changed Expand file tree Collapse file tree 2 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ visit the [main README][main-readme].
20
20
21
21
## Kotlin Extensions
22
22
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:
23
26
27
+ * [ ` firebase-firestore ` ] ( ./ktx/firestore.md )
24
28
25
29
[ android-setup ] : https://firebase.google.com/docs/android/setup
26
30
[ main-readme ] : https://github.com/firebase/firebase-android-sdk/blob/master/README.md
Original file line number Diff line number Diff line change 1
1
# Firestore Kotlin Extensions
2
2
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()
3
34
```
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 >()
5
67
```
You can’t perform that action at this time.
0 commit comments