尝试将Sqlite.swift查询作为数组返回时,Swift编译器出错

时间:2017-10-21 07:14:11

标签: arrays sqlite.swift

尝试将查询结果转换为数组。文档中的示例显示了这个工作......

let statement = try db.prepare(query)
var results = Array(statement)

...但是当我尝试编译时,我得到......

Ambiguous use of 'init'

...用于数组(语句)

如果我改变这个......

let statement = try db.prepare(query)
var results = Array<SQLite.Row>(statement)

我收到此错误...

Type of expression is ambiguous without more context

我可以做些什么来完成这项工作?

1 个答案:

答案 0 :(得分:0)

您需要遍历行以将它们放入数组中:

for statement in try db.prepare(query) {
    yourArray.append(statement)
}