Is there any simple examples of the ability to grab a variable from a function? For instance, if a certain thing happens in a function, then += 1 would be added to the variable. I'd like to grab that variable and use it in a Conditional statement in the View. Example below which I'm not sure how to work.
I have a function like so below:
func mspEL() -> Int {
var msp = 0
if age > 18 {
print("Elig")
msp += 1
} else {
print("No"
}
I have a View called ResultsView() which I'm trying to grab the msp variable from the function above and use it in a Conditional statement to show some Text. Eg; If the variable is greater than 0, write this Text.
struct ResultsView: View {
@State var result = msp
var body: some View {
if result > 0 {
Text("You are Eligible!")
} else {
print("")
}
}
}