I'm creating a math app and am trying to assign the correct answer to a variable. I've tried these two options below
@State private var correctAnswer1: Int {
number1L1 + number2L1
}
With this, I receive the error "Property wrapper cannot be applied to a computed property".
if currentLevel == 1
{
Text(" \(number1L1)")
.font(.system(size:70))
Text("+ \(number2L1)")
.font(.system(size:70))
Text("____")
.font(.system(size:70))
correctAnswer = number1L1 + number2L1
}
With this I receive the error "Type () cannot conform to 'View'"
How do I assign this variable without running into an error?
correctAnswer = number1L1 + number2L1. Remove@Statefrom your first snippet. Then, everything should run.correctAnswer = number1L1 + number2L1. In a View you should have other Views, this is what the error is telling you. From the code you show, it is clear you need to brush-up on the basics of SwiftUI , see for example: developer.apple.com/tutorials/swiftui To avoid the error, put that code inside a function.