Post

Replies

Boosts

Views

Activity

Reply to Generic input field for any numerical value with the associated unit
Thank you for your feedback. Unfortunately, this does not solve my problem. The function is supposed to be applicable for all possible (like UnitArea, UnitAcceleration, UnitAngle, ...). I wrote the following function which returns me the desired result as string. func showMeasurement(value: Double, unit: String, symbol: Bool) -> String {         switch(unit) {             //MARK: Aceleration         case "UnitAcceleration.metersPerSecondSquared":             let newValue = Measurement(value: value, unit: UnitAcceleration.metersPerSecondSquared)             if symbol {                 return newValue.unit.symbol             } else {                 return newValue.formatted(.measurement(width: .narrow, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(2))))             }         case "UnitAcceleration.UnitAcceleration":             let newValue = Measurement(value: value, unit: UnitAcceleration.baseUnit())             if symbol {                 return newValue.unit.symbol             } else {                 return newValue.formatted(.measurement(width: .narrow, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(2))))             } .... But later I will also need the corresponding Measurment to be able to calculate with the values.
Jun ’22
Reply to Picker Label not showing anymore
Try ``struct ExampleView: View { var fruits = ["Banana","Apple", "Peach", "Watermelon", "Grapes" ] @State private var selectedFruit = 0 var body: some View { VStack { Form { Picker(selection: $selectedFruit, label: Text("Select Favorite Fruit")) { ForEach(0..<fruits.count) { Text(self.fruits[$0]) } } Text("Your Favorite Fruit: \(self.fruits[selectedFruit])") } .pickerStyle(MenuPickerStyle()) } } }
Jun ’22