2016-09-26 37 views
1

我正在开发使用SQLite数据库的iOS应用程序,并使用SQLite.swift库(https://github.com/stephencelis/SQLite.swift)。SQLite.swift和Swift 3“模糊引用成员==”加入

我想我的应用程序迁移斯威夫特3,所以我改变了我的图书馆,当我尝试使用join使用分支swift3-mariotakuhttps://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)) 
    } 
} 

谢谢您的帮助

回答

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: [...] 
    ) 
相关问题