我正在開發使用SQLite數據庫的iOS應用程序,並使用SQLite.swift庫(https://github.com/stephencelis/SQLite.swift)。SQLite.swift和Swift 3「模糊引用成員==」加入
我想我的應用程序遷移斯威夫特3,所以我改變了我的圖書館,當我嘗試使用join
使用分支swift3-mariotaku
(https://github.com/stephencelis/SQLite.swift/tree/swift3-mariotaku)
我還有一個問題: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))
}
}
謝謝您的幫助