I am trying to format a measurement in my application as described in this documentation.
Notice the example code:
let temp = Measurement<UnitTemperature>(value: 38, unit: .celsius)
let formattedTemp = temp.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1))))
// For locale: en_US: 100.4 degrees Fahrenheit
When I try to do the same, I receive the following errors:
Cannot infer contextual base in reference to member 'fractionLength'
Cannot infer contextual base in reference to member 'numeric'
Extra argument 'numberFormat' in call
My code is as follows:
Text("\(current.temperature.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1)))))")
Where current is a CurrentWeather type provided by WeatherKit.
Why is my adherence to the documentation causing these errors?
Post
Replies
Boosts
Views
Activity
Apple Docs describe how to create a Swift executable to run Linux on an Intel based Mac, but the docs don't include the import statements required for the code to compile. I've determined I need to import both Cocoa and Virtualization but the following code from the final section Instantiate and Start the Virtual Machine is still generating an error:
let virtualMachine = VZVirtualMachine(configuration: configuration)
let delegate = Delegate() // Cannot find 'Delegate' in scope
virtualMachine.delegate = delegate
How do I resolve the Delegate() constructor?