Chronos is a collection of useful Grand Central Dispatch utilities.

Related tags

GCD Chronos-Swift
Overview

Overview

Build Status Version Carthage compatible Platform License git-brag-stats

Chronos is a collection of useful Grand Central Dispatch utilities. If you have any specific requests or ideas for new utilities, don't hesitate to create a new issue.

Utilities

  • DispatchTimer - A repeating timer that fires according to a static interval, e.g. "Fire every 5 seconds".
  • VariableTimer - A repeating timer that allows you to vary the interval between firings, e.g. "Fire according to the function interval = 2 * count."

Usage

Quick Start

CocoaPods

Add the following to your Podfile:

pod 'Chronos-Swift'
Carthage

Add the following to your Cartfile:

github "comyarzaheri/Chronos-Swift" "master"

Using a Dispatch Timer

import Chronos

var timer = DispatchTimer(interval: 0.25, closure: {
            (timer: RepeatingTimer, count: Int) in
                println("Execute repeating task here")
            })

/** Starting the timer */
timer.start(true) // Fires timer immediately

/** Pausing the timer */
timer.pause()

/** Permanently canceling the timer */
timer.cancel()

Using a Variable Timer

Double in return Double(2 * count) // Return interval according to function } /** Starting the timer */ timer.start(true) // Fires timer immediately /** Pausing the timer */ timer.pause() /** Permanently canceling the timer */ timer.cancel() ">
import Chronos

var variableTimer: VariableTimer = VariableTimer(closure: { 
            (timer: RepeatingTimer, count: Int) -> Void in
                println("Execute repeating task here")
        }) {(timer: VariableTimer, count: Int) -> Double in
                return Double(2 * count) // Return interval according to function
        }

/** Starting the timer */
timer.start(true) // Fires timer immediately

/** Pausing the timer */
timer.pause()

/** Permanently canceling the timer */
timer.cancel()

Requirements

  • iOS 8.0 or higher
  • OS X 10.10 or higher

License

Chronos is available under the MIT License.

Contributors

Comments
  • Build error -

    Build error -

    Hi, I must be doing something wrong.. I get the following error on lines 141 and 155:

    Initializer for conditional binding must have Optional type, not 'dispatch_source_t' (aka 'OS_dispatch_source')

    Any help appreciated..

    opened by daviddelmonte 9
  • Crash on iphone 5

    Crash on iphone 5

    Hi! I been using this library for a while and I like, thanks. The start function crash in when call scheduleRepeating due an overflow

    open func start(_ now: Bool) {
            validate()
            if OSAtomicCompareAndSwap32Barrier(State.paused, State.running, &running) {
              timer.scheduleRepeating(deadline: startTime(interval, now: now), interval: DispatchTimeInterval.nanoseconds(Int(interval.multiplied(by: Double(NSEC_PER_SEC)))))
                timer.resume()
            }
        }
    

    Also when you run the unit test in the iphone 5 you get this error message: "DispatchTimerTests.swift:38:96: Integer overflows when converted from 'UInt64' to 'Int'"

    I will make a pr for this issue. Thanks

    opened by ggiampietro 2
  • Build test error: Integer overflows

    Build test error: Integer overflows

    I got this error when build project with carthage.

    ChronosTests/DispatchTimerTests.swift:38:96: error: integer overflows when converted from 'UInt64' to 'Int' return DispatchTime(uptimeNanoseconds: DispatchTime.now().uptimeNanoseconds.advanced(by: Int(5 * NSEC_PER_SEC)))

    opened by lesslucifer 2
  • Not building with Carthage

    Not building with Carthage

    I am having building issues when trying to build with Carthage

    $ carthage bootstrap --platform iOS
    *** Checking out Chronos-Swift at "f6c02db716bdbc5404108fc06a6e61abcef4963e"
    *** Skipped building Chronos-Swift due to the error:
    Dependency "Chronos-Swift" has no shared framework schemes for any of the platforms: iOS
    

    Any thoughts?

    opened by schie 2
  • How to add a label to update

    How to add a label to update

    I can't get a label counter working with this lib, how to set it up?. I have a separate function which does the label update with NSTimer I used

    func fireProgress(timer: NSTimer) {
        self.valueLabel.text = self.timeRemaining
    }
    

    how can I do the same with this lib?

    opened by heshanlk 2
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    opened by ReadmeCritic 0
  • VariableTimer not repeating in background with delay greater than 5.0

    VariableTimer not repeating in background with delay greater than 5.0

    When delay <= 5.0 I get timer repeating forever as expected when app is in background. When I set delay larger, it fires once in background and then never repeats. (iOS10, Xcode8, Swift3)

    self.runLoopTimer = VariableTimer(closure: {
                    (timer: RepeatingTimer, count: Int) -> Void in
                    
                    <do stuff>
                    
                }) {(timer: VariableTimer, count: Int) -> Double in
                    DDLogVerbose("RunLoopMode -> \(self.runLoopMode):\(self.runLoopMode.rawValue)")
                    return self.runLoopMode.rawValue
                }
                
                self.runLoopTimer?.start(true)
    
    opened by bruce-lumo 0
  • DispatchTimer not using interval

    DispatchTimer not using interval

    No matter what I set the duration value to, it repeats as fast as possible, like every microsecond. (iOS10, Xcode8, Swift3)

    self.runLoopTimer = DispatchTimer(interval: 5.0 , closure: {
                    (timer: RepeatingTimer, count: Int) in
                    
                    <do stuff>
                })
    
                self.runLoopTimer?.start(true)
    
    opened by bruce-lumo 0
  • Adds OneShotTimer and OneShotDispatch Timer

    Adds OneShotTimer and OneShotDispatch Timer

    It might be a good idea to have a OneShotTimer, i.e. a timer that can only be run once after a certain delay.

    I've done some refactoring to RepeatingTimer in order to change the type of the closure. , so now there are 2 closure types:

    /**
    The closure to execute when the timer fires.
    
    - parameter timer:   The timer that fired.
    - parameter count:   The current invocation count. The first count is 0.
    */
    public typealias RepeatedExecutionClosure = ((RepeatingTimer, Int) -> Void)
    
    /**
     The closure to execute when the timer fires.
    
     - parameter timer:   The timer that fired. 
     */
    public typealias OneShotExecutionClosure = ((OneShotTimer) -> Void)
    

    I realise that this is a non-trivial change, but I'd welcome any feedback.

    opened by JeanAzzopardi 3
Releases(0.3.0)
Owner
Comyar Zaheri
Comyar Zaheri
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch

Async Now more than syntactic sugar for asynchronous dispatches in Grand Central Dispatch (GCD) in Swift Async sugar looks like this: Async.userInitia

Tobias Due Munk 4.6k Dec 27, 2022
iOS utility class to manage global dispatch queue.

YYDispatchQueuePool iOS utility class to manage global dispatch queue. (It's a component of YYKit) When use a concurrent queue to execute lots of bloc

null 464 Oct 31, 2022
Chronos is a collection of useful Grand Central Dispatch utilities.

Chronos is a collection of useful Grand Central Dispatch utilities. If you have any specific requests or ideas for new utilities, don't hesitate to create a new issue.

Comyar Zaheri 248 Sep 19, 2022
Chronos is a collection of useful Grand Central Dispatch utilities.

Overview Chronos is a collection of useful Grand Central Dispatch utilities. If you have any specific requests or ideas for new utilities, don't hesit

Comyar Zaheri 248 Sep 19, 2022
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch

Async Now more than syntactic sugar for asynchronous dispatches in Grand Central Dispatch (GCD) in Swift Async sugar looks like this: Async.userInitia

Tobias Due Munk 4.6k Dec 27, 2022
GCDTimer - Well tested Grand Central Dispatch (GCD) Timer in Swift

GCDTimer Well tested Grand Central Dispatch (GCD) Timer in Swift. Checkout the test file. Usage Long running timer import GCDTimer

Hemant Sapkota 183 Sep 9, 2022
Grand Central Dispatch simplified with swift.

GCDKit GCDKit is Grand Central Dispatch simplified with Swift. for Swift 1.2: Use version 1.0.1 for Swift 2.1 / 2.2: Use the master branch Introductio

John Estropia 317 Dec 6, 2022
A wrapper of Grand Central Dispatch written in Swift

GCD A wrapper of Grand Central Dispatch written in Swift. Examples gcd // submit your code for asynchronous execution on a global queue with high prio

Le Van Nghia 75 May 19, 2022
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (iOS7+ and OS X 10.9+ compatible)

Async.legacy Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (GCD) Async rewritten for iOS7 and OS X 10.9 Compatibility

Joseph Lord 31 Jul 1, 2019
Grand Central Dispatch simplified with swift.

GCDKit GCDKit is Grand Central Dispatch simplified with Swift. for Swift 1.2: Use version 1.0.1 for Swift 2.1 / 2.2: Use the master branch Introductio

John Estropia 317 Dec 6, 2022
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch

Async Now more than syntactic sugar for asynchronous dispatches in Grand Central Dispatch (GCD) in Swift Async sugar looks like this: Async.userInitia

Tobias Due Munk 4.6k Dec 27, 2022
A collection of operators and utilities that simplify iOS layout code.

Anchorage A lightweight collection of intuitive operators and utilities that simplify Auto Layout code. Anchorage is built directly on top of the NSLa

Rightpoint 620 Jan 3, 2023
A collection of socket utilities in pure Swift

SwifterSockets A collection of socket utilities in pure Swift SwifterSockets is part of the Swiftfire webserver project. The Swiftfire website The ref

Rien 58 Sep 9, 2022
A collection of common SwiftUI and UIKit utilities.

KippleUI A collection of common SwiftUI and UIKit utilities. ⚠️ The code in this library has been made public as-is for the purposes of education, dis

Kipple 10 Sep 2, 2022
A collection of common diagnostics and debugging utilities.

KippleDiagnostics A collection of common diagnostics and debugging utilities. ⚠️ The code in this library has been made public as-is for the purposes

Kipple 10 Sep 2, 2022
A collection useful tips for the Swift language

SwiftTips The following is a collection of tips I find to be useful when working with the Swift language. More content is available on my Twitter acco

Vincent Pradeilles 929 Dec 10, 2022
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Fabrizio Brancati 992 Dec 2, 2022
xTensions is a collection of useful class extensions for UIKit.

xTensions Intro xTensions is a collection of useful class extensions for UIKit. Swift Package Manager Note: Instructions below are for using SwiftPM w

Alexandre Garrefa 0 Nov 28, 2021
A collection of useful test helpers designed to ease the burden of writing tests for iOS applications.

MetovaTestKit is a collection of useful test helpers designed to ease the burden of writing tests for iOS applications. Requirements Installation Usag

null 23 Aug 29, 2021
BFKit is a collection of useful classes and categories to develop Apps faster.

Swift Version • What does it do • Language support • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog •

Fabrizio Brancati 806 Dec 2, 2022