Need a little help/guidance with the architecture / structure of the app I’m working on.
I have an array of “step” structs, and I need to loop through each step in the array and sequentially pass each struct to a StepView. StepView starts a timer, and when the timer expires, automatically closes.
struct ProtocolStep: Identifiable, Decodable {
let id:UUID=UUID()
var step: Int
var type: String
var time: Int // time in seconds
}
I have all of this working for ONE step using a simple NavigationLink. Here is my call:
NavigationLink(destination: StepView(sessionType: “protocol”, step:hotColdProtocol.protocolSteps[0]))
What I need help with is when StepView closes, I need the calling function/view to then pass the next “step” back into that StepView. Repeat until I’ve gone through all of the steps.
I still need the initial click on the NavigationLink to kick off the process, but once that happens I want the steps to be looped through automatically.
I guess I could also pass the entire array into my StepView and try to control everything inside that view…when the timer expires, get the next Step struct from the array passed in, set the relevant variables, and start the next timer…? (I just thought of this as I was typing out this post, actually.)
Appreciate any thoughts/advice/code/pseudocode you might have for doing something like this…