'I am getting error" Static method 'buildBlock' requires that 'UInt' conform to 'View'" when trying to read data from Firebase Realtime Database
I simply just want to read the data and store it in an int but I can't seem to read the data of any type without having an error. Please let me know if you need any addition information about the project
Code:
import FirebaseDatabaseSwift
import SwiftUI
import Firebase
struct InGameView: View {
var ref: DatabaseReference! = Database.database().reference()
var refOffset: DatabaseReference! = Database.database().reference().child("")
var body: some View {
refOffset.observe(.value) { DataSnapshot in
print(DataSnapshot)
}
}
}
Database Screenshot: enter image description here
Solution 1:[1]
It has nothing to do with FireBase. refOffset.observe(.value) does not return a view, therefore it shouldn't be used in var body. You may be able to make it compile by changing it to:
var body: some View {
let _ = refOffset.observe(.value) { DataSnapshot in
print(DataSnapshot)
}
}
but don't, that is very poor practice. A call like that should be in its own function, and called from an init() or .onAppear(), or as a result of some state change.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yrb |
