Metronome issue

I am trying to add a metronome feature to a music app. I have implemented the metronome as a class by using code from https://github.com/Nirma/Metronome and my app runs. However, after 1 second, the metronome slider resets back to zero. Is it something to do with the class being destroyed after 1 use? I'm not sure, so any solution would be appreciated.

 VStack {
            MetronomeView()

            Text("\(timeString(time: timeRemaining))")

                .font(.largeTitle)

                .foregroundColor(.white)

                .padding(.horizontal, 20)

                .padding(.vertical, 5)

                .background(Color.customColour.opacity(0.75))

                .clipShape(Capsule())

The above code shows how I have added the view into a VStack.

Answered by kian_tamjidi in 744695022

For anyone having the same issue, I managed to fix it: rather than declaring the object as an observable, I declared it as an @StateObject which worked.

Accepted Answer

For anyone having the same issue, I managed to fix it: rather than declaring the object as an observable, I declared it as an @StateObject which worked.

Metronome issue
 
 
Q