In the most excellent SQLite.swift, I have
let stmt = try local.db!.prepare(..)
for row in stmt {
for tricky in row {
each "tricky" is an Optional<Binding>
The only way I know to unwrap each tricky is like this
var printable:String = "
if let trickyNotNil = tricky {
if let anInt:Int64 = trickyNotNil as? Int64 {
print("it's an Int")
.. use anInt
}
if let aString:String = trickyNotNil as? String {
print("it's a String")
.. use aString}
}
else {
tricky is nil, do something else
}
In the example, I'm pretty sure it can only be either an Int64 or String (or something that goes to a String); I guess one would have to cover any other possibilities in there perhaps with a default case.
Is there a swiftyer way?
Is there are way to get the type of an Optional<Binding>
?
(BTW regarding, specifically, SQLite.swift; there may be a way I am unaware of from the doco to "get the type of column n". That would be cool, but, the question in the previous paragraph remains, in general.)