|
I am trying to dynamically create the parameters that are needed to pass into the measurement argument and then similarly for the conversion function, but my attempt to creat a string that looks like e.g. UnitSpeed.metersPerSecond and pass that as a variable into the Measurement or converted parameters is barking loudly. I could do this the long-handed way and create a bunch of if statements, but this seems like the most elegant route, if I can figure out how to pass the unit selections into the parameteres: (also...how do I add an image here and I will show a screenshot of where I am) |
|
Well, I went back and forth with Bard a few times...OMG... and the key insight is to use from: wihtin the unit area of Measurement, like this: Measurement(value: inValue, unit: unit(from: inputUnit)) This is where I ended up:
|
|
You might think to use this approach. Why do you need to convert back and forth strings when you can store measurements in array and use them.
As for how to post images from dropbox see that post https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-six-loops/25082/25091 |
|
@ygeras Yes, I wanted to do that. Thanks for showing me how to format the unit like that. |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.