swift - 使用带有转换参数的 try node.extract 符合 NodeInitializable

标签 swift swift3 vapor

我开始使用 Vapor,我正在尝试为名为 Intubationclass 创建模型。当您符合 NodeInitializable 时,您必须具有此功能:

init(node: Node, in context: Context) throws {
    intubationID = try node.extract("intubationID")
    attempt = try node.extract("attempt")
}

我收到有关 attempt = try node.extract("attempt") 行的错误说

调用中缺少参数“transform”的参数

如果 attemptclass Attempt 的实例,我该如何以正确的方式符合 NodeInitializable

最佳答案

Attempt 类也必须是 NodeInitializable 才能使 node.extract 调用正常工作。

extension Attempt: NodeInitializable { ... }

应该可以解决

关于swift - 使用带有转换参数的 try node.extract 符合 NodeInitializable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42928145/

相关文章:

ios - 在 UITableView 单元格滑动中选择 'Delete',但未调用 'commit editingStyle'

swift - 如何阅读此 Swift 语法?

vapor - 返回包含 Vapor 数组的 JSON

iOS UI 测试 : Cant Access elements - not in Elementtree

ios - 如何将值从 ViewController 传递到 UITableView 自定义单元格类

objective-c - 将方法从 Objective C 转换为 Swift

swift3 - Swift 包管理器,添加本地依赖

swift3 - 无法比较 Swift 3 中的 AnyHashable

ios - 从 Firebase 上传/下载数据时可以获得进度吗

Vapor 3 : transform array of Future object to an array of Future other objects