CaamDauTimer 4.0.0

CaamDauTimer 4.0.0

Maintained by lcd.



  • By
  • liucaide

CI Status Version License Platform

Timer

计时管理

pod 'CaamDauTimer'

pod 'CaamDau/Timer'

创建倒计时

func countDown(_ tag:Int){
        switch tag {
        case 0:// 代理接收
            Timer.make(.delegate(self, "123", 120, 0.1))
        case 1://广播
            Timer.make(.notification("456", 120, 0.1))
        case 2://闭包回调接收
            Timer.make(.callBack("789", 60, 0.1, { [weak self](model) in
                self?.lab_3.cd.text("\(model.day)天\(model.hour):\(model.minute):\(model.second):\(model.millisecond/100)")
            }))
        default:
            break
        }
    }

接收

extension ViewController:TimerProtocol {
    func cd_timer(withModel model: Timer.Model, id: String) {
        self.lab_1.cd.text("\(model.day)天\(model.hour):\(model.minute):\(model.second):\(model.millisecond/100)")
    }
}

NotificationCenter.default.rx
    .notification(Notification.Name(rawValue: "456"), object: nil)
    .asObservable()
    .subscribe(onNext: { [weak self](n) in
        if let model = n.object as? Timer.Model {
            self?.title = "\(model.day)天\(model.hour):\(model.minute):\(model.second)"
        }
    })
    .disposed(by: disposeBag)

deinit {
    //如果不需要保持 可以移除
    Timer.remove("456")
}