John
John

Reputation: 107

Why do I get 'No matches in call to initialiser' error when using Text?

A tad confused here, still very much learning obviously.

Running Xcode, with SwiftUI.

I have data which is being read (successfully) from a JSON file, and when I try to use Text() to output an Int, I get the dreaded "No exact matches in call to initialiser' error, yet all of the other items output to the screen perfectly fine.

The data items are declared correctly as either String or Int, but I get this error only when trying to output the Int.

                Text(question.question)
                Text(question.sylabusItem)
                Text(question.correct)
                Text(correctAnswer)
               

Any advice greatly appreciated. Thanks.

Upvotes: 1

Views: 45

Answers (1)

aheze
aheze

Reputation: 30336

Text has quite a lot of initializers. Out of these, one of them accepts a string.

However, none of them accept an Int.

To work around this you can use string concatenation.

Text("\(correctAnswer)") /// assuming correctAnswer is an Int

Upvotes: 1

Related Questions