Skip to content

Instantly share code, notes, and snippets.

@elkraneo
Created May 28, 2024 09:53
Show Gist options
  • Save elkraneo/e1cd603b598e609614cd7f71911a32e7 to your computer and use it in GitHub Desktop.
Save elkraneo/e1cd603b598e609614cd7f71911a32e7 to your computer and use it in GitHub Desktop.
struct ContentView: View {
let temperature = Measurement<UnitTemperature>(value: 13, unit: .celsius)
var body: some View {
List {
Text("let temperature = Measurement<UnitTemperature>(value: 13, unit: .celsius)")
.font(.headline)
Section("Implicit formatting") {
LabeledContent("temperature.formatted()", value: temperature.formatted())
LabeledContent(
"temperature.converted(to: .celsius).formatted()",
value: temperature.converted(to: .celsius).formatted())
}
Section("Explicit formatting: .measurement()") {
LabeledContent("temperature", value: temperature, format: .measurement())
LabeledContent(
"temperature.converted(to: .celsius)", value: temperature, format: .measurement())
}
Section("Explicit formatting: .measurement(usage: .asProvided))") {
LabeledContent(
"temperature.converted(to: .celsius)", value: temperature.converted(to: .celsius),
format: .measurement(usage: .asProvided))
LabeledContent(
"temperature.converted(to: .kelvin)", value: temperature.converted(to: .kelvin),
format: .measurement(usage: .asProvided))
}
}
.monospaced()
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment