admin管理员组文章数量:1336098
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])
本文标签:
版权声明:本文标题:swift - Why do I get "Subscript requires that Float conform to Value" when I try to select a field of type Flo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742403542a2468359.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论