将捕获块放入数组

时间:2018-12-26 19:02:49

标签: swift sqlite

我需要用文件中的Sqlite数据填充单元格。我有这段代码可以读取db并打印内容(用于测试),现在我想用它来填充单元格值(UIPickerView中的国家列表),但是要这样做,我需要尝试使用Connection在Do Catch块中,而[]不接受Do Catch块。我该怎么办?

do {
    // Database Connection
    let path = Bundle.main.path(forResource: "location", ofType: "sqlite")!
    db = try Connection(path, readonly: true)

    // Defino los parametros de la DB
    let code = Expression<Int64>("code")
    let name = Expression<String>("name")
    let num_levels = Expression<Int64>("num_levels")
    let levels_desc = Expression<String>("levels_desc")
    let paises = Table("country")

    for pais in try db.prepare(paises) {
        print("code: \(pais[code]), name: \(pais[name]), num_levels: \(pais[num_levels]), levels_desc: \(pais[levels_desc])")
    }
} catch {
    print("Error occurred \(error)")
}

cell.values = [


]

0 个答案:

没有答案