The most perfect Swift Timer you'll ever need.

Overview

Timerable

The most perfect Swift Timer you'll ever need.

A protocol-oriented Timer Factory with all the features you'll ever need. I wrote it in both RxSwift and Native Swift. hope you'll enjoy. If you find this useful don't forget to star ⭐️ .

features

  • Solved the background time problem: if your app state changes to background the timer won't stop and if you open the app you'll see the timer is still update.
  • Easy to use: Instead of making a timer for each part of your code easily use this few lines of codes.
  • Disposable: Instead of calling deinit to invalidate timer and remove the timer from memory manually just use this and it will do that automatically.
  • Protocol Oriented: You can conform to this protocol to easily use it.
  • Reactive
  • Testable
  • Developer friendly

Timerable

The Native Swift Timer. If you are using native swift and not using RxSwift you can use this file.

RxTimerable

The RxSwift Timer. If you are using RxSwift you can use this File.

Usage

  1. Simply just download and add RxTimerable or Timerable to your project.
  2. in the class or wherever you want to use this Timer simply add these lines of codes.

⚠️ For better understanding read the line by line code documentation ⚠️

let timer = TimeCounter()
let decreasingTime = TimeDecreasing(time: [.seconds(30)])
let increasingTime = TimeIncreasing(time: [.days(1), .minutes(34), .seconds(20)])
        
timer.setTimer(time: decreasingTime)
timer.start()
        
timer.timerDidEnd { in
    print("Time Ended ")
}

timer.bind { model in
    print("log", model)
}

Line by Line guideline

To use timer we need an instance:
let timer = TimeCounter()

To tell timer what to do, we need a set of rules so we can pass whatever conforms to Timerable Protocol to initial the timer:
timer.setTimer(time: Timerable)

I already made two type of Timerable in TimerModels.swift containing TimeIncreasing and TimeDecreasing.

For decreasing Timer you can use:
let decreasingTime = TimeDecreasing(time: [.seconds(30)])

For increasing Timer you can use:
let increasingTime = TimeIncreasing(time: [.days(1), .minutes(34), .seconds(20)])

After assigning initial values you MUST START the timer, to do so:
timer.start()

For binding to Timer there are two callbacks:

  1. For binding to update the UI or do something in each interval you must use:
timer.bind { model in
    print("log", model)
} 
  1. For binding to finishing timer you should use:
timer.timerDidEnd { in
    print("Time Ended ")
}

⚠️ Note: Do not forget to use `[weak self]` or `[unowned self]` to avoid retain cycle.
You might also like...
SwiftMoment - A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.

SwiftMoment This framework is inspired by Moment.js. Its objectives are the following: Simplify the manipulation and readability of date and interval

🕰 Type-safe time calculations in Swift

Time This micro-library is made for you if: You have ever written something like this: let interval: TimeInterval = 10 * 60 To represent 10 minutes. U

Intuitive date handling in Swift

Timepiece Intuitive date handling in Swift Features 💡 Intuitive: Timepiece provides a set of helpers to make date handling easier. 🕘 Correct: Using

NTP library for Swift and Objective-C. Get the true time impervious to device clock changes.
NTP library for Swift and Objective-C. Get the true time impervious to device clock changes.

TrueTime for Swift Make sure to check out our counterpart too: TrueTime, an NTP library for Android. NTP client for Swift. Calculate the time "now" im

Elegant NTP date library in Swift
Elegant NTP date library in Swift

Kronos is an NTP client library written in Swift. It supports sub-seconds precision and provides a stable monotonic clock that won't be affected by ch

Building a better date/time library for Swift

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

A Swift micro library for generating Sunrise and Sunset times.

Solar A Swift helper for generating Sunrise and Sunset times. Solar performs its calculations locally using an algorithm from the United States Naval

Custom Time Picker ViewController with Selection of start and end times in Swift 🔶
Custom Time Picker ViewController with Selection of start and end times in Swift 🔶

LFTimePicker Custom Time Picker ViewController with Selection of start and end times in Swift 🔶 . Based on Adey Salyard's design @ Dribbble One to tw

Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS.
Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS.

Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS. Installation Timekee

Owner
Emad Beyrami
iOS Developer @BornakGmbH
Emad Beyrami
Egg timer app written in Swift

Egg Timer Our Goal This module will be a mix of tutorials and challenges. Most importantly, we want you to get comfortable with looking up how to do s

null 0 Dec 2, 2021
This Control is a beautiful time-of-day picker heavily inspired by the iOS 10 "Bedtime" timer.

#10Clock Dark and Mysterious ?? Light Colors ?? Usage The control itsself is TenClock. Add that to your view hierarchy, and constrain it to be square

Joe 557 Dec 23, 2022
A timer that lets you know when your ramen is ready to eat!

Dependencies Ramen Timer requires the following: Gifu SwiftySound On Xcode simply go to File > Add Packages and input the names on the searchbar then

Angel Santiago 1 Nov 3, 2021
A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Lucas Ausberger 1 Jan 8, 2022
Typical master detail SAMPLE application written in Swift to test NY Times Most Popular API

NYTimes-Demo: Typical master detail SAMPLE application written in Swift to test NY Times Most Popular API. This SAMPLE application is written in Swift

Atif Naveed 0 Nov 3, 2021
A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

TimeZonePicker A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your

Gligor Kotushevski 125 Dec 13, 2022
Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

Dave DeLong 2k Dec 31, 2022
DateHelper - A high performant Swift Date Extension for creating, converting, comparing, or modifying dates.

DateHelper A high performant Swift Date Extension for creating, converting, comparing, or modifying dates. Capabilities Creating a Date from a String

Melvin Rivera 1.4k Jan 2, 2023
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!

Datez ?? Breeze through Date, DateComponents, and TimeInterval Highlights Two Custom Structs Only (value types FTW!): DateView: An Date associated wit

Kitz 263 Dec 7, 2022
SwiftDate 🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.

Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift. What's This? SwiftDate is the definitive toolchain to ma

Daniele Margutti 7.2k Jan 4, 2023