I'm having some difficultly grabbing a variable from a function and using it in a View for Text() purposes. I have a simple function like so:
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 get the msp
variable for an info statement like so:
struct ResultsView: View {
@State var result = msp
var body: some View {
if result > 0 {
Text("You are Eligible!")
} else {
print("")
}
}
}
But I'm unable to get this to work. As I mentioned, looking to see if the msp
variable is larger than 0 and if is, print Text in the View. What can I do to get this? Thanks!