蒸气 Swift 错误 "Reference to member 'sqlite' cannot be resolved without a contextual type"
Vapor Swift Error "Reference to member 'sqlite' cannot be resolved without a contextual type"
在全新安装 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
- Swift:
5.2
如果您能提供解决此错误的帮助,我们将不胜感激!如果我可以提供更多信息,请告诉我。谢谢!
是的,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)
在ToDo
class中添加typelias
,当你使用Swift5.2
final class Todo: SQLiteModel {
typealias Database = SQLiteDatabase
....
}
在全新安装 Vapor(来自 homebrew
)时,我调用:
vapor new Bridge
-> 成功vapor xcode
-> 成功y
(询问我是否要打开 Xcode 中的项目)-> 打开 Xcode 项目vapor --version
-> 3.1.10vapor 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
- Swift:
5.2
如果您能提供解决此错误的帮助,我们将不胜感激!如果我可以提供更多信息,请告诉我。谢谢!
是的,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)
在ToDo
class中添加typelias
,当你使用Swift5.2
final class Todo: SQLiteModel {
typealias Database = SQLiteDatabase
....
}