Skip to content

pablogm/PGMTimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PGMTimer

CI Status Version License Platform Carthage compatible

This is a simple class to provide a Swift Timer with the following features: start, stop, pause, resume.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation with CocoaPods

PGMTimer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PGMTimer"

Installation with Carthage

Carthage is another dependency management tool written in Swift.

Add the following line to your Cartfile:

github "pablogm/PGMTimer"

How to use

Init timer:

    timer = Timer(timerEnd: 10.0, timerWillStart: {

        print("Timer started.")
    
    }, timerDidFire: { [weak self] time in

        self?.timerLabel.text = time

    }, timerDidPause: {

        print("Timer paused")

    }, timerWillResume: {

        print("Timer resumed")

    }, timerDidStop: {

        print("Timer stopped")

    }, timerDidEnd: { [weak self] time in

        self?.timerLabel.text = time

    print("Timer End")
    })

Perform actions:

    @IBAction func startTimer(sender: UIButton) {

        if timer.state == .TimerStateUnkown || timer.state == .TimerStateStopped || timer.state == .TimerStateEnded {

            timer.start()
        }
        else {
            print("Can not start")
        }
    }

    @IBAction func pauseTimer(sender: UIButton) {

        if timer.state == .TimerStateRunning {

            timer.pause()
        }
        else {
            print("Can not pause")
        }
    }

    @IBAction func resumeTimer(sender: UIButton) {

        if timer.state == .TimerStatePaused {

            timer.resume()
        }
        else {
            print("Can not resume")
        }
    }

    @IBAction func stopTimer(sender: UIButton) {

        if timer.state == .TimerStateRunning {

            timer.stop()
        }
        else {
            print("Can not stop")
        }
    }

Support

Supports iOS8 and above. XCode 7.0 is required to build the latest code written in Swift 2.0

Author

Pablo GM, invanzert@gmail.com

License

PGMTimer is available under the MIT license. See the LICENSE file for more info.

About

This is a simple class to provide a Swift Timer with the following features: start, stop, pause, resume.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors