UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Day 19 Challenge: .formatted() causing trouble? ("Failed to produce diagnostic for expression; please submit a bug report")

Forums > 100 Days of SwiftUI

I have solved the Day 19 challenge, but I have yet another question:

Following this line in the Tips section: "Finally, if you’d like to be a bit fancy with the output number you display, try calling .formatted() on it – e.g. someDouble.formatted()", I thought I'd get "a bit fancy" and so I changed my Text view to:

Text(outputTemp.formatted(), format: .number)

But now on my var body: some View { line, I'm getting a compiler error: "Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project". (Thanks, that's very helpful... NOT).

What gives?

Thanking you in advance.

1      

.formatted() returns a formatted String.

Text(_:format:) is for displaying non-String values.

You should pick one way or the other, but not both.

//either

Text(outputTemp.formatted())

//or

Text(outputTemp, format: .number)

1      

Ah, that makes sense. Thank you so much. I should've inspected the documentation carefully before posting! Cheers!

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.