Просмотр исходного кода

Fix race condition if no autotune profile has existed before.

Jan Dittmer 4 лет назад
Родитель
Сommit
fc97a9d06f

+ 5 - 1
FreeAPS/Sources/Modules/AutotuneConfig/View/AutotuneConfigRootView.swift

@@ -73,7 +73,11 @@ extension AutotuneConfig {
                                         Text(rateFormatter.string(from: autotune.basalProfile[index].rate as NSNumber) ?? "0")
                                         Text("U/hr").foregroundColor(.secondary)
                                     }
-                                    if let basalProfile = state.basalProfile[index] {
+                                    // To prevent a race condition if Autotune is ran an no profile
+                                    // existed before.
+                                    if state.basalProfile.indices.contains(index),
+                                       let basalProfile = state.basalProfile[index]
+                                    {
                                         HStack {
                                             Text("Pump")
                                             Text(basalProfile.displayTime)