Search code examples
swiftapple-watchwatchos

Cannot infer contextual base in reference to member 'fractionLength'


I'm trying to follow this screencast on building an app for Apple Watch. I've updated Xcode to 13.3, but I'm getting an error that doesn't appear in the screencast.

Cannot infer contextual base in reference to member 'fractionLength'

Cannot infer contextual base in reference to member 'numeric'

Extra argument 'numberFormat' in call

Text(
    Measurement(
        value: 47,
        unit: UnitEnergy.kilocalories
    ).formatted(
        .measurement(
            width: .abbreviated,
            usage: .workout,
            numberFormat: .numeric(precision: .fractionLength(0))
            )
        )
    )

enter image description here


Solution

  • maybe things have changed. You could try this instead:

    Text(Measurement( value: 47, unit: UnitEnergy.kilocalories)
            .formatted(
                .measurement(
                    width: .abbreviated,
                    usage: .workout,
                    numberFormatStyle: .number.precision(.fractionLength(0))
                )
            )
    )