I’ve got a pretty simple problem with adding negative numbers, but Apple Documentation doesn’t really cover this.
SwiftUI Code:
Text(String(-50 + 5))
This throws the error, Compiling failed: Ambiguous use of operator '-'
. However, Text(String(-50))
doesn’t throw any errors.
I’ve tried casting -50 as an Int and wrapping it in parentheses. Also, if I assign -50 + 5
to a variable, and then use the variable in the Text(), it works fine. How can I get this to display -45, and what’s causing the error?
Note: Using XCode 13.2.1 on macOS Monterey
EDIT: People are asking for a screenshot, as it seems the issue isn’t occurring for everyone. Here’s the issue in a brand new project.
2
Answers
Check out Canvas diagnostics:
and tell Xcode which type you wanna use:
e.g.
or
See the error, it probably code can’t reconize -50 to int.
So I test for some example like this is wrok.