我正在尝试将数据保存在firebase上,然后从该数据库中获取数据,但是看到此错误。我尝试了许多链接,但未找到任何帮助?谢谢前进...
import UIKit
import GoogleMaps
import FirebaseCore
import Firebase
import FirebaseDatabase
class ViewController: UIViewController {
var databaseRefer: DatabaseReference!
var databaseHandle: DatabaseHandle!
override func viewDidLoad() {
super.viewDidLoad()
databaseRefer = Database.database().reference()
databaseRefer.child("name").childByAutoId().setValue("England")
databaseRefer.child("name").childByAutoId().setValue("Pakistan")
DatabaseHandle =
databaseRefer.child("name").observe(.childAdded, with: {
(data) in
let name = (data.value as? String)
debugPrint(name)
})
}
Geting this Error at this line...
DatabaseHandle = databaseRefer.child("name").observe(.childAdded,
with: { (data) in
let name = (data.value as? String)
debugPrint(name)
})
无法分配给'DatabaseHandle.Type'类型的不可变表达式 (又名“ UInt.Type”)
答案 0 :(得分:0)
尝试通过以下方式获取数据:
let ref = Database.database().reference(withPath: "YOUR_CHILD_NAME")
ref.observeSingleEvent(of: .value) { (snapshot) in
if !snapshot.exists() { return }
print("DATA RECEIVED FROM FIREBASE!!!")
print(snapshot.value)
}