Setting global variable with Cloud Firestore on Kotlin
问题 again :) I got a question about Cloud Firestore and Kotlin. I need to get data from firestore with some code like this: { val comments = mutableListOf<Comment>() val firestore = FirebaseFirestore.getInstance() firestore.collection(collection).document(documentID).collection("comments") .addSnapshotListener { querySnapshot, firebaseFirestoreException -> comments = querySnapshot?.toObjects(Comment::class.java)!! // do something with 'comments'. Works: comments is populated } // do something