-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentTemperature.swift
More file actions
31 lines (26 loc) · 1.05 KB
/
CurrentTemperature.swift
File metadata and controls
31 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import SwiftUI
struct CurrentTemperature: View {
@ObservedObject var bluetooth: Bluetooth
init(@ObservedObject bluetooth:Bluetooth) {
self.bluetooth = bluetooth
}
var body: some View {
let currentTemperature = bluetooth.currentTemperature/10
let displayTemperature = (bluetooth.isF ? bluetooth.cToF(temperatureInCelcius: currentTemperature) : currentTemperature)
let temperatureSuffix = bluetooth.isF ? "F" : "C"
let validTemperatures = 40...230
Text("\(validTemperatures.contains(currentTemperature) ? "\(displayTemperature)°\(temperatureSuffix)" : "")")
.font(.largeTitle)
.foregroundColor(.orange)
.onTapGesture {
if (validTemperatures.contains(currentTemperature)){
bluetooth.SetIsF(useF: !bluetooth.isF)
}
}
}
}
struct CurrentTemperature_Previews: PreviewProvider {
static var previews: some View {
CurrentTemperature(bluetooth: Bluetooth.init())
}
}