Hello guys, I am new to swiftUI and I meet the error "Updating took more than 5 seconds" when I add the following code
@State var studentclass = "default"
@State var studentNumber = "default"
@State var targetedArrayIndex : Int = 1
@State var isActive = false
.
.
.
.
.
NavigationLink(destination: Result(result : results[targetedArrayIndex]), isActive: $isActive) {
Button(action: {
if studentclass == "1A" && studentNumber == "01" {targetedArrayIndex = 0}
if studentclass == "1A" && studentNumber == "02" {targetedArrayIndex = 1}
if studentclass == "1A" && studentNumber == "03" {targetedArrayIndex = 2}
.
.
.
.
self.isLinkActive = true
}) {.....}
In the above code, I am trying to read the result of a particular student from a json file stored in an array. I created a dropdown menu that allow user to select studentclass and studentNumber. Hence, I use the IF/THEN statement to judge the array index of the targeted student. However, once I pass the targetedArrayObject to Result.swift (which is another view for displaying student's result), Xcode report an error.
For debuging, I tried to replace the varible targetedArrayObject by 0, i.e.
NavigationLink(destination: Result(result : results[0]), isActive: $isActive) {.....}
It works and shows the result sucessfully.
So I get confused of why I get an error in the first case.