Skip to content

Instantly share code, notes, and snippets.

@oogatta
Last active October 2, 2017 17:15
Show Gist options
  • Save oogatta/de4f841c6195be5efaa914b4c50bd1d4 to your computer and use it in GitHub Desktop.
Save oogatta/de4f841c6195be5efaa914b4c50bd1d4 to your computer and use it in GitHub Desktop.
// ☁️ Admin node
admin.database().ref().child("test").child("Admin")
.once("value", snapshot => {
Object.values(snapshot.val()).forEach(value => {
console.log(`(${value.hoge}, ${value.fuga})`);
});
});
// 🍎 iOS Swift
Database.database().reference().child("test").child("iOS")
.observe(.value, with: { snapshot in
snapshot.children.allObjects
.flatMap { ($0 as? DataSnapshot)?.value as? [String: Int] }
.forEach { print(($0["hoge"] ?? -1, $0["fuga"] ?? -1)) }
})
// 🤖 Android Kotlin
FirebaseDatabase.getInstance().reference.child("test").child("Android")
.addListenerForSingleValueEvent(object: ValueEventListener {
override fun onCancelled(p0: DatabaseError?) {}
override fun onDataChange(snapshot: DataSnapshot?) {
snapshot?.children?.forEach {
println(it.getValue<Hoge>(Hoge::class.java)?.hoge to it.getValue<Hoge>(Hoge::class.java)?.fuga)
}
}
})
// 🛎 結果はすべて
(1, 5)
(2, 4)
(3, 3)
(4, 2)
(5, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment