I am developing an iOS app using Swift 3 and the GRDB SQLite library. The following code fragment causes a compile error of "value of type '[Row]' has no member 'next'"
let rows = try Row.fetchAll(db, sql, arguments:arguments)
while let row = try rows.next() { <--- line with error
...
}
As far as I can tell I am following the example in the docs correctly. Can anyone tell me what I am doing wrong?
The
fetchAllmethod returns a regular Swift array, that you iterate like all other arrays:The
nextmethod belongs to cursors, that you get with thefetchCursormethod. Cursors are not arrays because they don't load all database results in one step. Instead, cursors are iterated row after row:You see that both arrays and cursors can iterate database results. How do you choose one or the other? Look at the differences:
Compare:
If you don't see, or don't care about the difference, use arrays. If you care about memory and performance, use cursors when appropriate.
Link to the documentation: https://github.com/groue/GRDB.swift/blob/master/README.md#fetching-methods