StopWatch

class StopWatch : NSObject

This class handles the logic behind a stop watch timer It has two statuses: started or stopped. When started it counts time. when stopped it does not count time.

  • Temporary elapsed time.

    Declaration

    Swift

    var tmpElapsedTime: TimeInterval
  • Time the stopwatch started

    Declaration

    Swift

    var startedTime: TimeInterval
  • Current status

    Declaration

    Swift

    var status: StopWatchStatus
  • Defines the interval in which the delegate is called

    Declaration

    Swift

    var timeInterval: TimeInterval
  • Timer that handles the synchronous notifications calls to updateElapsedTime

    Declaration

    Swift

    var timer: Timer
  • Delegate that receives the time updates every timeInterval

    Declaration

    Swift

    weak var delegate: StopWatchDelegate?
  • Initializes the stopWatch with elapsed time 0.00 and stopped stop watch status.

    Declaration

    Swift

    override init()
  • Start counting time

    Declaration

    Swift

    func start()
  • Stops counting time

    Declaration

    Swift

    func stop()
  • Sets everything to 0.0

    Declaration

    Swift

    func reset()
  • Current elapsed time.

    Declaration

    Swift

    var elapsedTime: TimeInterval { get }
  • Returns the elapsed time as a String with the format MM:SS or HhMM:SS

    Examples:

    1. if elapsed time is 3 min 30 sec, returns 03:30
    2. 3h 40 min 30 sec, returns 3h40:20

    Declaration

    Swift

    var elapsedTimeString: String { get }
  • Calls the delegate (didUpdateElapsedTimeString) to inform there was an update of the elapsed time.

    Declaration

    Swift

    @objc
    func updateElapsedTime()