问题描述:

How do you get at a row of type SQLite.Row using the row number?

This is order to populate a picker using the results Array.

Thanks

var allCountries:Array<Any>?

let countries = Table("Country")

let id = Expression<Int64>("rowid")

let name = Expression<String>("Name")

let code = Expression<String>("Code")

func pickerView(_ pickerView:UIPickerView, titleForRow row: Int, forComponent component:Int) -> String?{

return allCountries?[row].*somethingHere* as String

//The array is populated with rows of type SQLite.Row

}

func getCountries() -> Array<Any>{

var results:Array<Any>?

do{

let path = Bundle.main.path(forResource: "location", ofType: "sqlite")

let db = try Connection(path!, readonly: true)

results = Array(try db.prepare(countries))

}

catch{

print("Error")

}

return results!

}

网友答案:

Resolved - needed to return an Array<SQLite.Row>, not <Any>.

相关阅读:
Top