Some code is not allowed to be inside an if.
For example how can I call a func inside an if?
why if you add a simple "print("Hello")" we get that alarm??
That's because, in the body, SwiftUI builds views, and only views. And print(…) is a func that returns Void: signature is (), as reported in alert.
So, to do what you want, you need to put in the func: var anothervariable = 0
struct ContentView: View {
let un = 1
let deux = 2
func one() -> some View {
print("Hello")
return Text("One")
}
func two() -> some View {
anothervariable = un + deux
print(anothervariable)
return Text("Two")
}
var body: some View {
if un > deux {
one()
} else {
two()
}
}
}