I've been working with Sqlite.Swift for quite a while now and I'm stuck.
I'm trying to get an Int
out of the .count
of only the amount of rows containing the String
value "1" in the column "yes or no".
I've been using the following function to randomly pick a row only once (without repeating). I thought this must be a good start to define the .count
for only the described rows but I have absolutely no clue if this'd be possible.
This is how I got my "row randomizer" working:
func randomNumber() -> Int {
var randomNumber = Int(arc4random_uniform(UInt32(try! database.scalar(table.select(ItemId.distinct.count)))))
while pickedNumber == randomNumber {
randomNumber = Int(arc4random_uniform(UInt32(try! database.scalar(table.select(ItemId.distinct.count)))))
}
pickedNumber = randomNumber
return randomNumber
}
let randomRow = randomNumber()
thanks!