CYTimer
a swift timer。Avoid problems with native Timer class strong references, stalls, inaccuracies, etc.
Install / Use
/learn @CocoaYog/CYTimerREADME
CYTimer
A swift timer。Avoid problems with native Timer class strong references, stalls, inaccuracies, etc.
Feature
- Based entirely on swift.
- Without any dependency.
- Support custom queue.
- Use Block to avoid strong reference issues with
target. - Stable and accurate.
- Memory security.
Usage
Drag the CYTimer folder to your project,and follow the example below:
/*
ATTENTION :
After the timer is created, it must be held by an instance, otherwise it will be destroyed immediately
PARAMETER :
queue : Specify the timer to run the queue, Default `main queue`
timeInterval : Specify timer interval
repeats : Mark timer to repeat tasks
isIMEXE : Whether the timer is executed immediately after it is created。This parameter is only valid for reaped timer. Default `false`
*/
timer = CYTimer.init(queue: DispatchQueue.init(label: "custom-queue"), timeInterval: 2, repeats: true, isIMEXE: true, block: {[weak self] (timer) in
self?.timerAction()
})
/*
Call the timer methods without worrying about memory problems or crashes
*/
// The timer suspend
timer?.suspend()
// The timer start or restart
timer?.resume()
//The timer cancel.If you want to use it again, you need to reset the timer
timer?.cancel()
// reset the timer
func resetTimer(_ sender: UIButton) {
timer?.timer(queue: DispatchQueue.global(), timeInterval: 4, repeats: true, block: { [weak self](_) in
self?.timerAction()
})
}
Related Skills
node-connect
352.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
