From 4f31622abe3adb18d8362658b3cfc49ad63d3fe8 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Fri, 2 May 2025 23:15:01 +0200 Subject: [PATCH] Fix label editing view --- .../Views/Pages/Commands/LabelCreationView.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CHDataManagement/Views/Pages/Commands/LabelCreationView.swift b/CHDataManagement/Views/Pages/Commands/LabelCreationView.swift index 15bf2b8..5a25434 100644 --- a/CHDataManagement/Views/Pages/Commands/LabelCreationView.swift +++ b/CHDataManagement/Views/Pages/Commands/LabelCreationView.swift @@ -10,7 +10,7 @@ struct LabelCreationView: View { var body: some View { List { - ForEach($labels) { label in + ForEach($labels, id: \.icon) { label in HStack { Button(action: { remove(label.wrappedValue) }) { Image(systemSymbol: .minusCircleFill) @@ -32,13 +32,13 @@ struct LabelCreationView: View { } private func addLabel() { - var label = ContentLabel(icon: .statisticsTime, value: "Value") - var number = 0 - while labels.contains(label) { - number += 1 - label.value = "Value \(number)" + for icon in PageIcon.allCases { + if labels.contains(where: { $0.icon == icon }) { + continue + } + labels.append(.init(icon: icon, value: "Value")) + return } - labels.append(label) } private func remove(_ label: ContentLabel) {