Home

Awesome

<br> <p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/Mijick/Assets/blob/main/Timer/Logotype/On%20Dark.svg"> <source media="(prefers-color-scheme: light)" srcset="https://github.com/Mijick/Assets/blob/main/Timer/Logotype/On%20Light.svg"> <img alt="Timer Logo" src="https://github.com/Mijick/Assets/blob/main/Timer/Logotype/On%20Dark.svg" width="76%""> </picture> </p> <h3 style="font-size: 5em" align="center"> Modern API for Timer </h3> <p align="center"> Easy to use yet powerful Timer library. Keep your code clean </p> <p align="center"> <a href="https://github.com/Mijick/Timer-Demo" rel="nofollow">Try demo we prepared</a> | <a href="https://mijick.notion.site/122683c582c8441fa4b4bbb00290598e?v=f7b570720ff94414835ed7894dbacd96&pvs=25" rel="nofollow">Roadmap</a> | <a href="https://github.com/Mijick/Timer/issues/new" rel="nofollow">Propose a new feature</a> </p> <br> <p align="center"> <img alt="SwiftUI logo" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/Language.svg"/> <img alt="Platforms: iOS, iPadOS, macOS, tvOS" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/Platforms.svg"/> <img alt="Current Version" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/Version.svg"/> <img alt="License: MIT" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/License.svg"/> </p> <p align="center"> <img alt="Made in Kraków" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/Origin.svg"/> <a href="https://twitter.com/MijickTeam"> <img alt="Follow us on X" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/X.svg"/> </a> <a href=mailto:team@mijick.com?subject=Hello> <img alt="Let's work together" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/Work%20with%20us.svg"/> </a> <a href="https://github.com/Mijick/Timer/stargazers"> <img alt="Stargazers" src="https://github.com/Mijick/Assets/blob/main/Timer/Labels/Stars.svg"/> </a> </p> <p align="center"> <img alt="Timer Examples" src="https://github.com/Mijick/Assets/blob/main/Timer/GIFs/Timer.gif"/> </p> <br>

Timer is a free and open-source library dedicated for Swift that makes the process of handling timers easier and much cleaner.

<br>

Getting Started

✋ Requirements

PlatformsMinimum Swift Version
iOS 13+5.0
iPadOS 13+5.0
macOS 10.15+5.0

⏳ Installation

Swift package manager

Swift package manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding Timer as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/Mijick/Timer", branch(“main”))
]

Cocoapods

Cocoapods is a dependency manager for Swift and Objective-C Cocoa projects that helps to scale them elegantly.

Installation steps:

    pod init
    pod 'MijickTimer'
    pod install

Usage

1. Initialise the timer

Call the publish() method that has three parameters:

  try! MTimer.publish(every: 1, currentTime: $currentTime)

2. Start the timer

Start the timer using the start() method. You can customise the start and end time using the parameters of this method.

  try! MTimer
      .publish(every: 1, currentTime: $currentTime)
      .start(from: .init(minutes: 21, seconds: 37), to: .zero)

3. (Optional) Observe TimerStatus and TimerProgress

You can observe changes in both values by calling either of the methods

  try! MTimer
      .publish(every: 1, currentTime: $currentTime)
      .bindTimerStatus(isTimerRunning: $isTimerRunning)
      .bindTimerProgress(progress: $timerProgress)
      .start(from: .init(minutes: 21, seconds: 37), to: .zero)

4. Stop the timer

Timer can be stopped with stop() method.

  MTimer.stop()

5. Additional timer controls

  try! MTimer.resume()
  MTimer.reset()

6. Displaying the current time as String

You can convert the current MTime to String by calling the toString() method. Use the formatter parameter to customise the output.

  currentTime.toString {
      $0.unitsStyle = .full
      $0.allowedUnits = [.hour, .minute]
      return $0
  }

7. Creating more timer instances

Create a new instance of the timer and assign it to a new variable. Use the above functions directly with it

  let newTimer = MTimer.createNewInstance()

  try! newTimer
      .publish(every: 1, currentTime: $currentTime)
      .start()

  newTimer.stop()
<br>

Try our demo

See for yourself how does it work by cloning project we created

License

Timer is released under the MIT license. See LICENSE for details.

<br><br>

Our other open source SwiftUI libraries

PopupView - The most powerful popup library that allows you to present any popup <br> NavigationView - Easier and cleaner way of navigating through your app <br> CalendarView - Create your own calendar object in no time <br> GridView - Lay out your data with no effort <br> CameraView - The most powerful CameraController. Designed for SwiftUI