A swift wrapper for NSTimer

Related tags

Utility Every.swift
Overview

Every.Swift - A Convenient NSTimer Wrapper

Usage

Provided that your class implement TimerManageable protocol you just do:

self.every(3.seconds) {
    print("hello")
    return true
}

Prints "hello" every 3 seconds.

Return true from the closure to continue , false to invalidate the timer.

Alternatively , you can use the following method to invalidate all timers of the receiver: self.clearTimers()

Normally you're are responsible of invalidating the timers you created. If the timer is not invalidated before the object it's been tied to it will be invalidated next time the timer is elapsed and before calling the ElapsedHandler.

TODO :

  • Investigate automatic invalidation of timer if owner is Swift object.
  • Add a project and test target.
  • Improve unit test coverage.
  • Support milliseconds.
  • Embed in a framework.
  • More representative example application.
  • OS X support.
  • Carthage support.
  • CocoaPod support.
Comments
  • Rewrite of the code to make it follow Swift guidelines

    Rewrite of the code to make it follow Swift guidelines

    I got rid of the Objective-C API dependency. I made it the swift-way. I don't think it's a good thing to extend all NSObject instances. It's better to make some sort of new API and write dedicated objects to handle it.

    This way I think it's clearer and more secure.

    Ideally I'll rewrite it to be a Cocoa framework. I had to put some structs and classes into the same file, a framework would make it easier to put each struct and class in its own file.

    opened by Pyroh 5
  • Not really an issue but milliseconds seems to work with this...

    Not really an issue but milliseconds seems to work with this...

    Add this to NSDateComponentsExtensions.swift

    public var nanoseconds: NSDateComponents { let components = NSDateComponents.zero() components.nanosecond = self return components }

    opened by hippymulehead 1
  • made the TimerManageable protocol's extension's methods public

    made the TimerManageable protocol's extension's methods public

    When installing via cocoapods, the default implementations of TimerManageable's methods are not used. Swift asks the user to implement them in the conforming class. Declaring methods as public solves the issue.

    opened by binchik 0
  • Added unit tests for clear timer methods.

    Added unit tests for clear timer methods.

    Three new tests for next methods:

    • TimerManager.clearAllTimers()
    • TimerManager.clearTimersForOwner(owner: AnyObject)
    • TimerManager.clearTimer(handler: TimerHandler)
    opened by arthur-here 0
  • Master

    Master

    • You no longer need to extends NSObject to use Every. Every class that implement the TimerManageable protocol can take avantage of the lib.
    • No more explicit auto-deallocation. But it can be delayed and done when timer is elapsed.
    opened by Pyroh 0
Owner
Samhan Salahuddin
Samhan Salahuddin
๐Ÿ’ก A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift.

UTIKit UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift. Features UTIKit is a full featured library including entire UTI functions. Conver

Hiroki Kato 254 Nov 27, 2022
A Swift property wrapper which stores the previous value

swift-with-previous A Swift property wrapper which stores the previous value. The previous value can be get by the projected value $propertyName. impo

IKEDA Sho 3 Feb 22, 2022
Swift wrapper for PuLP module.

SwiftPuLP Wraps Python Linear Programming PuLP module. Requirements Requires PuLP to be installed, and may require PYTHON_LIBRARY environment variable

Michel Tilman 0 Dec 24, 2021
Coz profiler Swift wrapper/bindings

Swift Coz (Linux Only) Coz profiler Swift wrapper/bindings. This is a Swift wrapper around the Coz profiler here: https://github.com/plasma-umass/coz

Krzysztof Majk 4 Aug 5, 2022
An unofficial wrapper around FSEvent tailored for Swift 5.

EonilFSEvents Eonil 2018 Maintenance. 2019 Maintenance. It's possible to use FSEvents directly in Swift, but it still involves many boilerplate works

eonil 87 Dec 24, 2022
A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.

Bookmark A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed. This class wraps Swift's URL

Darren Ford 8 Nov 3, 2022
Backports the new @Invalidating property wrapper to older platforms

ViewInvalidating A property wrapper that backports the new @Invalidating property wrapper to older versions of iOS/tvOS/macOS. For more information on

Suyash Srijan 61 Nov 23, 2022
Dungeon Crawl: Stone Soup iOS Webtiles wrapper

dcss-ios Dungeon Crawl: Stone Soup iOS Webtiles wrapper Summary This project aims to make DCSS webtiles a joy to play on any iOS device without an ext

Jon Lazar 2 Aug 10, 2022
Contacts wrapper for iOS 9 or upper with Objective-C

ContactsWrapper Contacts wrapper for iOS 9 or upper with Objective-C. For the information translated to Russian, take a look at this link. Requirement

Abdullah Selek 22 Jun 18, 2022
StoredIn is a simple property wrapper library to store any value in anywhere

StoredIn StoredIn is a simple property wrapper library to store any value in anywhere. Installation Please use the Swift Package Manager. dependencies

Henrique Sasaki Yuya 2 Jul 4, 2022
`Republished` is a property wrapper enabling nested ObservableObjects in SwiftUI.

Republished The @Republished proprty wrapper allows an ObservableObject nested within another ObservableObject to naturally notify SwiftUI of changes.

Adam Zethraeus 13 Dec 5, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC โ€” A โ€œnot-for-profitโ€ benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - โœ๏ธSwift ๊ณต๋ถ€ ์ €์žฅ์†Œโœ๏ธ

Swift ์Šค์œ„ํ”„ํŠธ์˜ ๊ธฐ์ดˆ 1. Swift์˜ ๊ธฐ๋ณธ 2. ๋ณ€์ˆ˜์™€ ์ƒ์ˆ˜ [3. ๋ฐ์ดํ„ฐ ํƒ€์ž… ๊ธฐ๋ณธ] [4. ๋ฐ์ดํ„ฐ ํƒ€์ž… ๊ณ ๊ธ‰] 5. ์—ฐ์‚ฐ์ž 6. ํ๋ฆ„ ์ œ์–ด 7. ํ•จ์ˆ˜ 8. ์˜ต์…”๋„ ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ๊ณผ ์Šค์œ„ํ”„ํŠธ 9. ๊ตฌ์กฐ์ฒด์™€ ํด๋ž˜์Šค 10. ํ”„๋กœํผํ‹ฐ์™€ ๋ฉ”์„œ๋“œ 11. ์ธ์Šคํ„ด์Šค ์ƒ

Jiwon 0 Mar 9, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022