With SQLite.swift 0.15.3 in XCode 16 I'm trying to select a field of type Float but I get an error assigning it a variable. The field is defined as let iAmount = Expression<Float>("Amount");
. When I try to populate a variable I get:
Subscript 'subscript(_:)' requires that 'Float' conform to 'Value'
The code:
for ri in try db.prepare(dtRecipeIngredients.order(iName).where(iUUIDRecipe == r[rUUID]))
{
let amount : Float = ri[iAmount]
let newIngredient = Ingredient (
Name: ri[iName]
, Qnty: amount
)
The error occurs at compile time, not run time. Should I be declaring the expression for the field in a different way for a Float? I'm able to use String and Data type.
With SQLite.swift 0.15.3 in XCode 16 I'm trying to select a field of type Float but I get an error assigning it a variable. The field is defined as let iAmount = Expression<Float>("Amount");
. When I try to populate a variable I get:
Subscript 'subscript(_:)' requires that 'Float' conform to 'Value'
The code:
for ri in try db.prepare(dtRecipeIngredients.order(iName).where(iUUIDRecipe == r[rUUID]))
{
let amount : Float = ri[iAmount]
let newIngredient = Ingredient (
Name: ri[iName]
, Qnty: amount
)
The error occurs at compile time, not run time. Should I be declaring the expression for the field in a different way for a Float? I'm able to use String and Data type.
Share edited Nov 20, 2024 at 0:03 user4157124 3,00214 gold badges31 silver badges46 bronze badges asked Nov 19, 2024 at 19:22 Mike MathesonMike Matheson 1 1- 1 Did you try Double? github/stephencelis/SQLite.swift/blob/master/Documentation/… – Joakim Danielson Commented Nov 19, 2024 at 19:34
1 Answer
Reset to default 0Swift Float
simply doesn't conform to Value
(this is a protocol declared by SQLite.swift).
Use Double
instead, which does conform to Value
. This makes sense, because floating point numbers in SQLite are always 8 bytes.
let iAmount = Expression<Double>("Amount")
You can convert it to a Float
after you get the column's value if you like,
let amount = Float(ri[iAmount])