gpt4 book ai didi

ios - 快速从 firebase 读取数据但无法显示。可能是变量作用域错误

转载 作者:行者123 更新时间:2023-11-28 11:40:29 24 4
gpt4 key购买 nike

<分区>

`

import UIKit
import FirebaseDatabase
import FirebaseAuth
class mapVC: UIViewController {
var name:String = ""
var number:String = ""

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.setHidesBackButton(true, animated:true);
var dict = fetchData()
print(dict)

}
func fetchData()->[String:String]{
var ref: DatabaseReference!
ref = Database.database().reference()
var uid:String=""
var email:String=""
let user = Auth.auth().currentUser
if let user = user {
let uid_local = user.uid
let email_local = user.email
uid=uid_local
email=email_local!
}
ref.child("Users").child(uid).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
self.name = value?["name"] as? String ?? ""
print(value?["name"] as? String ?? "")
self.number = value?["number"] as? String ?? ""
print(value?["number"] as? String ?? "")
})
return(["Name":name,"Number":number,"Email":email,"UID":uid]);
}
}

在 Swift 中从 firebase 读取数据但无法显示。可能是变量作用域错误。 print(value?["name"] as?String ?? ""的输出是预期结果)但未分配给 self.name 变量。我相信这是一个范围错误,但我还不确定。非常感谢所有帮助,因为我是 iOS 和 Swift 的新手。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com