Error: `'(@lvalue String) -> Text' is not convertible to '(String) -> Text'` in SwiftUI

Viewed 1710

Occasionally, when using Text(_:) in SwiftUI, I get the error '(@lvalue String) -> Text' is not convertible to '(String) -> Text'. This happens completely randomly, and is independent of the SwiftUI View or the contents of the text. It occasionally fixes itself, other times I have to restart my computer, other times I have to make a new SwiftUI file. So I'm wondering if this error actually means anything or if it's just a beta bug? Thanks.

Note: I am not including any other code as this happens in any SwiftUI file regardless of any other code. It is completely dependent on Text

2 Answers

This error occurs if you have any item in a stack that has the wrong type, i.e. a type that is not convertible to String. The same error can occurs in the code below:

Text("Hello world")
Text(100)

The strange part is that the error occurs on the first row, even though it is the second row that fixes it. I would verify that you are only using strings in all your Text() to see if that helps.

EDIT: Apparently it can happen no matter what error occurs in the body. It seem that the error occurs on the first item in the body if anything is wrong.

I found that errors in SwiftUI are a bit strange now, i almost never pointed to right error, so check you code to find error somewhere, it could be something else, not only the line that xcode tells you.

Related