Mercurial > public > lazybear
comparison LazyBear/Views/Company/Helpers/KeyStatsList.swift @ 448:f71761f166f2
Handle when data is empty
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 23 Jun 2021 11:47:14 +0200 |
parents | 8621ba6fd457 |
children |
comparison
equal
deleted
inserted
replaced
447:8621ba6fd457 | 448:f71761f166f2 |
---|---|
14 var body: some View { | 14 var body: some View { |
15 Form { | 15 Form { |
16 let mirror = Mirror(reflecting: keyStats) | 16 let mirror = Mirror(reflecting: keyStats) |
17 ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class | 17 ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class |
18 if let unwrappedValue = unwrapAnyOptional(value: child.value) { | 18 if let unwrappedValue = unwrapAnyOptional(value: child.value) { |
19 let label = String(child.label!) | 19 if unwrappedValue != "0.000" && unwrappedValue != "0" && !unwrappedValue.isEmpty { |
20 HStack { | 20 let label = String(child.label!) |
21 Text("\(displayWords.keyStats[label]!):") | 21 HStack { |
22 .font(.callout) | 22 Text("\(displayWords.keyStats[label]!):") |
23 .fontWeight(.semibold) | 23 .font(.callout) |
24 .lineLimit(1) | 24 .fontWeight(.semibold) |
25 | 25 .lineLimit(1) |
26 Spacer() | 26 |
27 Text(unwrappedValue) | 27 Spacer() |
28 .font(.callout) | 28 Text(unwrappedValue) |
29 .lineLimit(1) | 29 .font(.callout) |
30 .lineLimit(1) | |
31 } | |
30 } | 32 } |
31 } | 33 } |
32 } | 34 } |
33 } | |
34 } | |
35 | |
36 /* | |
37 Unwrap optional Int, Double, String into String | |
38 */ | |
39 private func unwrapAnyOptional(value: Any) -> String? { | |
40 if let value = value as? Int { | |
41 return "\(value)" | |
42 } else if let value = value as? Double { | |
43 return String(format: "%.3f", value) | |
44 } else { | |
45 return value as? String | |
46 } | 35 } |
47 } | 36 } |
48 } | 37 } |
49 | 38 |
50 struct KeyStatsList_Previews: PreviewProvider { | 39 struct KeyStatsList_Previews: PreviewProvider { |