Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- a/LazyBear/Views/Company/Helpers/KeyStatsList.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/KeyStatsList.swift Wed Jun 23 11:47:14 2021 +0200 @@ -16,35 +16,24 @@ let mirror = Mirror(reflecting: keyStats) ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class if let unwrappedValue = unwrapAnyOptional(value: child.value) { - let label = String(child.label!) - HStack { - Text("\(displayWords.keyStats[label]!):") - .font(.callout) - .fontWeight(.semibold) - .lineLimit(1) - - Spacer() - Text(unwrappedValue) - .font(.callout) - .lineLimit(1) + if unwrappedValue != "0.000" && unwrappedValue != "0" && !unwrappedValue.isEmpty { + let label = String(child.label!) + HStack { + Text("\(displayWords.keyStats[label]!):") + .font(.callout) + .fontWeight(.semibold) + .lineLimit(1) + + Spacer() + Text(unwrappedValue) + .font(.callout) + .lineLimit(1) + } } } } } } - - /* - Unwrap optional Int, Double, String into String - */ - private func unwrapAnyOptional(value: Any) -> String? { - if let value = value as? Int { - return "\(value)" - } else if let value = value as? Double { - return String(format: "%.3f", value) - } else { - return value as? String - } - } } struct KeyStatsList_Previews: PreviewProvider {