这是代码片段:
import SQLite
import Foundation
//---------line 12 -------- ↓
var idCol : Expression<Int64> = Expression("ID") // column variable that represents the ID column
//---------line 60 -------- ↓
func insert(tbl: Table, cols: Expression<Int64> ..., vals: Int64 ...){
do {
...
}
//---------line 101 -------- ↓
func createTable(pk: Expression<Int64>, cols: Expression<Int64> ...) {
// run the create table if the database connection exists and it doesn't exist already.
if let definiteDB = db {
do {
try _ = definiteDB.scalar(tbl.exists)
//print("table exists")
} catch {
do {
//print("table does not exist")
try definiteDB.run(tbl.create() {t in
t.column(pk, primaryKey: .autoincrement)
})
for col in cols {
try definiteDB.run(tbl.addColumn(notNullToNull(expr: col)))
}
} catch let error {
print(error)
}
}
}
}
}
第 12、60 和 101 行发生错误(在代码片段中标记)。错误是
'Expression' is ambiguous for type lookup in this context
我可以修改什么才能构建文件。我正在尝试在 xcode cloud 上构建它
iOS 18/macOS 15 SDK 现在在 Expression
中包含一个名为
Foundation
的新类型。这似乎只是 Predicate
的一个版本,只不过它可以输出任何类型,而不仅仅是 Bool
。
这会导致与
Expression
中声明的 SQLite
类型发生名称冲突。您需要写 SQLite.Expression
来澄清。或者您可以声明类型别名:
typealias SQLExpression = SQLite.Expression