Future in let answerID = try -6ren">
gpt4 book ai didi

swift - Vapor Swift 流利 : Type of expression is ambiguous without more context

转载 作者:搜寻专家 更新时间:2023-10-30 23:11:50 24 4
gpt4 key购买 nike

这是我的路线:

router.get("answers","delete", Int.parameter) { req -> Future<Response> in

let answerID = try req.parameters.next(Int.self)
guard let _ = getUsername(req) else {
throw Abort(.unauthorized)
}
return Message.query(on: req).filter(\.id == answerID).first().map(to: Response.self) { answer in
guard let answer = answer else {
throw Abort(.notFound)
}
return answer.delete(on: req).map(to: Response.self) { _ in
return req.redirect(to: "/answers")
}
}
}

但是对于 xCode,如果没有更多的上下文,这是不明确的 .filter(\.id == answerID)

这是我的结构消息:

struct Message: Content, SQLiteUUIDModel, Migration {
var id: UUID?
var username: String
var content: String
var category: String
var question: String
var date: Date

我不明白,因为我在许多其他路由中对 id 使用过滤器,这是我第一次显示此错误。

我在谷歌上搜索了一下,似乎在未导入 Fluent 时会出现错误,但我已经在顶部import Fluent

最佳答案

我刚刚有时间测试你的代码。如果你更换

...   .map(to: Response.self) { answer in ....

... .flatMap(to:Response.self) { answer in ...

有效。

关于swift - Vapor Swift 流利 : Type of expression is ambiguous without more context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53536298/

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