GCDTimer
An implementation of timer which supports GCD queue with some practical features like pause/resume in Objective-C and Swift
Install / Use
/learn @hossein1448/GCDTimerREADME
GCDTimer
An implementaiton of timer which supports GCD queue with some practical features such as
- fire and invalidatein
- pause
- resume
- remaining time
in Objective-C and Swift.
Why we use GCDTimer
- We love Grand Central Dispatch!.
- Apple has not announced any APIs for NSTimer/Timer which supports GCD properly.
- The API for using NSTimer/Timer which supports block/clousre just work for iOS 10+. It means we have to handle the iOS versions programatically and choose a proper way to use NSTimer/Timer.
- NSTimer retain cycle issue, NSTimer will maintain a strong reference to the target, which can cause (especially in repeating timers) strong reference cycles (a.k.a. retain cycles)
Requirements
- iOS 7.0+
- Swift 4.0+
- Objective-C
How to use
Create an GCDTimer object with the init method in Objective-C:
GCDTimer *timer = [[GCDTimer alloc] initWithTimeout:2.0 repeat:true completion:^{
<#code#>
} queue:dispatch_get_main_queue()]
in Swift:
let timer = GCDTimer(timeout: 2.0, repeat: true, completion: {
<#code#>
}, queue: DispatchQueue.main)
Please Check out the code in the test targets for more.
Related Skills
openhue
338.7kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
338.7kElevenLabs text-to-speech with mac-style say UX.
weather
338.7kGet current weather and forecasts via wttr.in or Open-Meteo
tweakcc
1.5kCustomize Claude Code's system prompts, create custom toolsets, input pattern highlighters, themes/thinking verbs/spinners, customize input box & user message styling, support AGENTS.md, unlock private/unreleased features, and much more. Supports both native/npm installs on all platforms.
