swift函数返回(),但值是存在的其他事物
我向firebase打了一个getData()。我的价值正确,并且将其存储到一个变量(Ergebnis)中。 问题是,我无法返回值。我会收到以下错误:void函数中意外的非空隙返回值'如何从任务中返回它?
func holDaten(Daten: String) async throws -> String{
let ref = Database.database().reference()
let kurstxt = UserDefaults.standard.value(forKey: "aktuellerKurs") as! String
ref.child("\(kurstxt ?? "default value")/\(Daten ?? "")").getData(completion: { error, snapshot in
guard error == nil else {
print(error!.localizedDescription)
return;
}
let Ergebnis = Task{ () -> String in
do{
let Ergebnis = await snapshot?.value as? String ?? "Unknown";
return Ergebnis
}
catch{
return("Nichts")
print("Error")
}
}
return Ergebnis
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要用
with checkedthrativeContinuation
这样You will need to wrap your call to
getData
withwithCheckedThrowingContinuation
like this