Error with AppStorage (SwiftUI)

Hi! I am trying to make a variable increase its value when pressing a button and if that value is greater than 2, +1 is added to another variable, I did it with an if that and at the time of writing that variable 2 adds its value tells me : Type '()' cannot conform to 'View'

Code Block
struct SwiftUIView: View {
    @AppStorage ("num1") var num1: Int = 0
    @AppStorage ("num2") var num2: Int = 0
        var body: some View {
            VStack{
                    num1 = 2
                if num1 > 2
                {
                    num2 += 1
                }
            }
    }
}

Your code does not make sense. Where is button? You are writing executable statements where Views are required.

Put a button and write executable statements inside the action closure of the button.
Accepted Answer
Sorry, I misspelled the code, actually it is

Code Block
@AppStorage ("num1") var num1: Int = 0
@AppStorage ("num2") var num2: Int = 0
var body: some View {
VStack{
Button(action: {
num1 += 1
}) {
Image("+1")
.resizable()
}
if num1 > 2
{
num2 += 1
}
}

Accepted Answer
Not a big difference.

Executable code such as
Code Block
if num1 > 2
{
num2 += 1
}

needs to be in an action closure of the button.

Line 13...16 is a place to put Views, not the place for executable statements.
Thank you very much for the help!
Error with AppStorage (SwiftUI)
 
 
Q