将个人的名字从 firebase 读取到 swift 中的 UILabel

Read the first name of an individual from firebase into a UILabel in swift

我成功地读取了个人的名字,并且可以在控制台中打印这个值,但是我怎样才能成功地将它传递到 UILabel 中呢?

当我尝试如下所示传递它时,出现错误 "Value of type '(viewController) -> () -> viewController' has no member 'FirstName'"

var ref: 数据库引用!

var FirstName: String?

func observeName() { // this is the function that will return the name of the individual to ensure that it is displayed on the HomeViewController
    guard let uid = Auth.auth().currentUser?.uid else { return }

    let ref = Database.database().reference().child("users").child("profile").child(uid)
    ref.queryOrderedByKey().observeSingleEvent(of: .value, with: { (snapshot) in

        let value = snapshot.value as? NSDictionary
        let firstName = value?["First Name"] as? String
        self.FirstName = firstName
    }) { (error) in
        print(error.localizedDescription)
    }
}


let welcomeText: UILabel = {
    let l = UILabel()
    l.text = "Hi...\(self.FirstName)"// WHERE I WANT THE NAME!!
    l.font = UIFont(name: "Optima-ExtraBlack", size: 30)
    l.textColor = .white
    return l
}()

我希望这是 return 刚刚登录的用户的名称。任何帮助都会很棒!一直在旋转我的车轮。

在 firebase 函数的完成处理程序中设置 welcomeText.text = firstName