SwiftUI - How to Make A Start/Stop Timer
问题 My goal is to create a view in SwiftUI that starts with 0. When you press the view, a timer should start counting upwards, and tapping again stops the timer. Finally, when you tap again to start the timer, the timer should begin at 0. Here is my current code: import SwiftUI struct TimerView: View { @State var isTimerRunning = false @State private var endTime = Date() @State private var startTime = Date() let timer = Timer.publish(every: 0.001, on: .main, in: .common).autoconnect() var tap: