更新时间:2022-05-01 23:00:17
这很hacky.
您应该在init
方法中添加completionHandler
.因此,当您的异步调用完成时,您将获得对象的实际值.
You should add completionHandler
in init
method. So, when your asynchronous call completed you will get actual value of object.
init(snapshot: DataSnapshot, completionHandler: @escaping (User) -> Void) {
self.uid = snapshot.key
getFirebasePictureURL(userId: uid) { (url) in
self.getFirebaseNameString(userId: self.uid) { (fullName) in
self.fullName = fullName
self.profilePictureURL = url
completionHandler(self)
}
}
}
我希望这会对您有所帮助.
I hope this will help you.