【问题标题】:Vapor Swift Error "Reference to member 'sqlite' cannot be resolved without a contextual type"Vapor Swift 错误“如果没有上下文类型,就无法解析对成员‘sqlite’的引用”
【发布时间】:2020-03-25 12:16:07
【问题描述】:

在全新安装 Vapor 时(来自 homebrew),我致电:

  • vapor new Bridge -> 成功
  • vapor xcode -> 成功
  • y(询问我是否要在 Xcode 中打开项目)-> 打开 Xcode 项目
  • vapor --version -> 3.1.10
  • vapor build -> 失败

我得到的错误是:

[1/3] Compiling App configure.swift
/Users/josh/Applications/Xcode/Projects/Bridge/Sources/App/configure.swift:31:49: error: reference to member 'sqlite' cannot be resolved without a contextual type
    migrations.add(model: Todo.self, database: .sqlite)
                                               ~^~~~~~
[2/3] Compiling App app.swift

版本号:

  • macOS:10.15.3 (19D76)
  • Xcode:11.4 (11E146)
  • 蒸气:3.1.10
  • 斯威夫特:5.2

任何帮助找出如何解决此错误,我们将不胜感激!让我知道我是否可以提供更多信息。谢谢!

【问题讨论】:

  • 嘿,我认为mistdon的回答是最好的

标签: swift vapor


【解决方案1】:

是的,Vapor 3 在 Swift 5.2 上遇到编译问题
https://forums.swift.org/t/vapor-3-swift-5-2-regression/34764

migrations.add(model: Todo.self, database: .sqlite)

上述代码在 Swift 5.1 中编译良好,现在将导致以下错误:

Reference to member 'sqlite' cannot be resolved without a contextual type

这可以通过使用显式类型而不是前导点语法来解决:

migrations.add(model: Todo.self, database: DatabaseIdentifier<SQLiteDatabase>.sqlite)

【讨论】:

  • 谢谢!这让它运行了!仅供参考,我将DatabaseIdentifier&lt;SQLiteDatabase&gt;.sqlite 更改为DatabaseIdentifier&lt;Todo.Database&gt;.sqlite。
【解决方案2】:

当您使用 Swift 5.2

时,在 ToDo 类中添加 typelias
final class Todo: SQLiteModel {

    typealias Database = SQLiteDatabase

    ....
}

【讨论】:

  • 是的,谢谢!这应该被接受的答案
猜你喜欢
  • 1970-01-01
  • 2020-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多