Learn Courses My Dashboard

14 Day Beginner Challenge (SwiftUI) - Lesson 11 Challenge

Hello everyone.

I don’t understand what I am doing wrong in this challenge. The error message I get on line 18 is as follows:

“No exact matches in call to initializer”

But don’t I “call” or declare the value earlier under “struct ContentView” ?

Maybe var value is float not a text you need put “” in 18 line

Won’t adding quotes turn it into a string?
As in like: Text(“value”)

Sorry I’m not entirely sure what you mean.

value is an Int, as evidenced by you initializing it as such:

@State var value = 0

Text does not have an initializer that takes an Int. You need to convert it to a string, for example by using string interpolation:

Text("\(value)")

Also…

When posting code to these forums, please post the code as text rather than an image. This makes it far easier to read (some of us have aging eyes!) and also makes it possible for other posters to copy/paste the code in order to test solutions and such.

To post your code as text, place three backticks ``` on the line before your code and three backticks ``` on the line after your code so that it will be formatted properly. You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you.

Ah perfect!! That did the trick! Another question though: is…

Text("\(value)")

… the same as:

Text(String(value))

I did the one above just now but i was curious as to whether or not one was inherently better than the other.

Also sorry!! I’ll make sure to do that in future posts. Thank you!

Yes, they are essentially the same. String interpolation is more powerful and efficient, but in a simple case like this it really makes no difference.