Latest 0.1.3
Homepage https://github.com/pablogm/PGMTimer
License MIT
Platforms ios 8.0, requires ARC
Frameworks Foundation
Authors

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, [email protected]

License

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

Latest podspec

{
    "name": "PGMTimer",
    "version": "0.1.3",
    "summary": "Swift Timer: start, stop, pause, resume.",
    "description": "This is a simple class to provide a Swift Timer with the following features: start, stop, pause, resume.",
    "homepage": "https://github.com/pablogm/PGMTimer",
    "license": "MIT",
    "authors": {
        "Pablo GM": "[email protected]"
    },
    "source": {
        "git": "https://github.com/pablogm/PGMTimer.git",
        "tag": "0.1.3"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "PGMTimer": [
            "Pod/Assets/*.png"
        ]
    },
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This