作者:喝西北风的东北风_711 | 来源:互联网 | 2023-10-17 10:47
我想将结果转换为ModelA数组,但没有找到方法。
let query = "SELECT t1.columnA,t2.columnB from table1 as t1,table2 as t2 ..."
let results = try! db.prepare(query) as Array() // I do not know how to cast
ModelA:
Struct ModelA: Codable{
let columnA: String
let columnB: String
}
您不能直接投射,请尝试在结果上使用map
let models = results.map { ModelA(columnA: $0[0],columnB: $0[1] }