Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscript 'subscript(_:)' requires that 'Float' conform to 'Value' #1287

Open
ipodsync opened this issue Nov 19, 2024 · 1 comment
Open

Subscript 'subscript(_:)' requires that 'Float' conform to 'Value' #1287

ipodsync opened this issue Nov 19, 2024 · 1 comment

Comments

@ipodsync
Copy link

ipodsync commented Nov 19, 2024

Issues are used to track bugs and feature requests.
Need help or have a general question? Ask on Stack Overflow (tag sqlite.swift).

Build Information

SQLite.swift version : 0.15.3
XCode : 16
Swift Package manager

I'm trying to select a field of type Float but I get an error assigning it to a variable.

The field is defined as:
let iAmount = Expression<Float>("Amount");

When I try to populate a variable, I this the error:
Subscript 'subscript(_:)' requires that 'Float' conform to 'Value'

Below is 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?

@ipodsync
Copy link
Author

ipodsync commented Nov 19, 2024

The same thing will work with a Int type, but not Float.

The error occurs on this line:
let amount : Float = ri[iAmount]

I was able to get my code working by switching to a Double:
let iAmount = Expression<Double>("Amount");

The documentation does state that Float should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant