我正在开发一个使用SQLite数据库的iOS应用程序,并使用SQLite.swift库(https://github.com/stephencelis/SQLite.swift)。
我尝试在Swift 3中迁移我的应用程序,因此我更改了我的库以使用分支swift3-mariotaku
(https://github.com/stephencelis/SQLite.swift/tree/swift3-mariotaku)
当我尝试使用join
:Ambiguous reference to member ==
这是我的代码:
class ArticlesDAO {
static let articles = Table("Article")
static let id = Expression<Int?>("id")
}
class FiltresVehiculesDAO {
let vfiltres = Table("VFiltre")
let idVehi = Expression<Int?>("vehicule")
func get(_ idVehicule: Int) throws -> [FiltreVehicule] {
let sqlQuery = vfiltres.join(
ArticlesDAO.articles,
// Next Line : "Ambiguous reference to member ==" error
on: vfiltres[idArticle] == ArticlesDAO.articles[ArticlesDAO.id]
)
//[...]
}
}
经过几次搜索,我找到了这个帖子Swift 3 URLSession.shared() Ambiguous reference to member 'dataTask(with:completionHandler:) error (bug)。所以我尝试在on
参数中应用指定返回类型的解决方案,如下所示:
on: (vfiltres[idArticle] == ArticlesDAO.articles[ArticlesDAO.id]) as Expression<Bool?>
我也尝试精确地确定每个元素:
on: ((vfiltres[idArticle] as Expression<Int?>) == (ArticlesDAO.articles[ArticlesDAO.id] as Expression<Int?>)) as Expression<Bool?>
错误仍然相同。
我检查了库代码,但我不知道如何解决这个问题,所以这是使用的库代码,也许应该有助于理解:
join
方法:
public func join(_ table: QueryType, on condition: Expression<Bool>) -> Self {
return join(table, on: Expression<Bool?>(condition))
}
==
重载:
public func ==<V : Value>(lhs: Expression<V>, rhs: Expression<V>) -> Expression<Bool> where V.Datatype : Equatable {
return "=".infix(lhs, rhs)
}
String
扩展名(infix
方法):
extension String {
func infix<T>(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression<T> {
let expression = Expression<T>(" \(self) ".join([lhs, rhs]).expression)
guard wrap else {
return expression
}
return "".wrap(expression)
}
func wrap<T>(_ expression: Expressible) -> Expression<T> {
return Expression("\(self)(\(expression.expression.template))", expression.expression.bindings)
}
func wrap<T>(_ expressions: [Expressible]) -> Expression<T> {
return wrap(", ".join(expressions))
}
}
感谢您的帮助
答案 0 :(得分:1)
我找到了解决方案,我的问题不在XCode设计的行中(我认为它可能是Xcode 8构建器中的一个问题)。
问题出在下一行,我没有更改.LeftOuter
中的.leftOuter
:
let sqlQuery = vfiltres
.join(
ArticlesDAO.articles,
on: ArticlesDAO.articles[ArticlesDAO.id] == vfiltres[idArticle]
)
.join(
.leftOuter, // was : .LeftOuter
DesignationsDAO.designations,
on: [...]
)