Mike Rose
Mike Rose

Reputation: 11

Stopwatch Lap Timer

I have created a simple stopwatch following a tutorial on Youtube but I have found that pressing the 'lap' button just gives me the current time the timer is at.

The only way I can think of doing this is having a timer running in the background that prints the time the button is pressed but resets after that.

Is there an easier way?!

This is the first project I have done and I am still getting to grips the with basics.

Here's the lap-related code:

@IBAction func lapReset(sender: AnyObject) {

    if addLap == true {

        laps.insert(stopwatchString, atIndex: 0)
        lapsTableView.reloadData()


    }else {

        addLap = false

        lapresetButton.setImage(UIImage(named: "lapButton.png"), forState: .Normal)

        laps.removeAll(keepCapacity: false)
        lapsTableView.reloadData()


        fractions = 0
        seconds = 0
        minutes = 0

        stopwatchString = "00:00.00"
        stopwatchLabel.text = stopwatchString


    }


}

Thanks, Mike

Upvotes: 0

Views: 1138

Answers (1)

Mike Rose
Mike Rose

Reputation: 11

Solved. I added a separate timer that reset every time I pressed 'lap' and also posted the lap time on the tableview.

Upvotes: 0

Related Questions