Swiftpack.co -  moliya/EasyTimer as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
moliya/EasyTimer
轻量级的倒计时触发器
.package(url: "https://github.com/moliya/EasyTimer.git", from: "1.2.0")

EasyTimer

轻量级的计时器

示例图

Kapture1

概述

EasyTimer是轻量级的计时器,能帮助你轻松管理倒计时等功能。可对UITableViewCellUICollectionViewCell中的倒计时进行统一管理。

要求

  • Swift 5.0 / Objective-C
  • Xcode 11
  • iOS 9.0+

使用


EasyTimerupdater支持传入遵循EasyTimerUpdater协议的对象,也可以传入UITableViewUICollectionView对象,EasyTimer会自动查找遵循EasyTimerUpdaterCell对象,然后触发回调方法func timerUpdate(interval: TimeInterval)

Swift
//初始化EasyTimer
self.timer = EasyTimer()
//初始化EasyTimer,并传入updater和触发间隔
self.timer = EasyTimer(updater: self, interval: 0.5)
//启动
timer.run()
//停止
timer.pause()
//updater为ViewController,则ViewController实现EasyTimerUpdater协议的回调方法
extension ViewController: EasyTimerUpdater {
    func timerUpdate(interval: TimeInterval) {
      	//在这里更新倒计时
        print(interval)
    }
}

//updater为UITableView或UICollectionView,则对应Cell实现EasyTimerUpdater协议的回调方法
extension UITableViewCell: EasyTimerUpdater {
    func timerUpdate(interval: TimeInterval) {
      	//在这里更新cell的倒计时
        print(interval)
    }
}
Objective-C
//初始化EasyTimer
self.timer = [[KFEasyTimer alloc] init];
//初始化EasyTimer,并传入updater和触发间隔
self.timer = [[KFEasyTimer alloc] initWithUpdater:self interval:0.5];
//启动
[self.timer run];
//停止
[self.timer pause];
//updater为ViewController,则ViewController实现EasyTimerUpdater协议的回调方法
@interface ViewController ()<KFEasyTimerUpdater>
@end

@implementation ViewController
- (void)timerUpdateWithInterval:(NSTimeInterval)interval {
    //在这里更新倒计时
}
@end

//updater为UITableView或UICollectionView,则对应Cell实现EasyTimerUpdater协议的回调方法
@interface TableViewCell ()<KFEasyTimerUpdater>
@end

@implementation TableViewCell
- (void)timerUpdateWithInterval:(NSTimeInterval)interval {
    //在这里更新cell的倒计时
}
@end

集成

CocoaPods
pod 'KFEasyTimer'
Swift Package Manager
dependencies: [
    .package(url: "https://github.com/moliya/EasyTimer", from: "1.2.0")
]

License

EasyTimer is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

2 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API