How to use a Decimal as @Property of AppEntity

I’m trying to use a Decimal as a @Property in my AppEntity, but using the following code shows me a compiler error. I’m using Xcode 16.1.

The documentation notes the following:

You can use the @Parameter property wrapper with common Swift and Foundation types:

  • Primitives such as Bool, Int, Double, String, Duration, Date, Decimal, Measurement, and URL.
  • Collections such as Array and Set. Make sure the collection’s elements are of a type that’s compatible with IntentParameter.

Everything works fine for other primitives as bools, strings and integers. How do I use the Decimal though?

Code

struct MyEntity: AppEntity {
    var id: UUID
    
    @Property(title: "Amount")
    var amount: Decimal

    // …
}

Compiler Error

This error appears at the line of the @Property definition:

Generic class 'EntityProperty' requires that 'Decimal' conform to '_IntentValue'
Answered by DTS Engineer in 817345022

Hi @alexander216,

The documentation notes the following:

You can use the @Parameter property wrapper with common Swift and Foundation types:

  • Primitives such as Bool, Int, Double, String, Duration, Date, Decimal, Measurement, and URL.
  • Collections such as Array and Set. Make sure the collection’s elements are of a type that’s compatible with IntentParameter.

Please note that the linked documentation describes the @Parameter property wrapper, not the @Property wrapper. I can see how that could cause confusion at a glance.

Best,

-J

Accepted Answer

Hi @alexander216,

The documentation notes the following:

You can use the @Parameter property wrapper with common Swift and Foundation types:

  • Primitives such as Bool, Int, Double, String, Duration, Date, Decimal, Measurement, and URL.
  • Collections such as Array and Set. Make sure the collection’s elements are of a type that’s compatible with IntentParameter.

Please note that the linked documentation describes the @Parameter property wrapper, not the @Property wrapper. I can see how that could cause confusion at a glance.

Best,

-J

How to use a Decimal as @Property of AppEntity
 
 
Q