Skip to content

Instantly share code, notes, and snippets.

@jackyshan
Created May 15, 2017 03:06
Show Gist options
  • Save jackyshan/4d92b8de1f0fc793748b0952bc158cbf to your computer and use it in GitHub Desktop.
Save jackyshan/4d92b8de1f0fc793748b0952bc158cbf to your computer and use it in GitHub Desktop.
rxswift实现定时器
let interval = Observable<Int>.interval(0.6, scheduler: MainScheduler.instance)
let disinterval = interval.subscribe(onNext: { (time) in
guard time < lines.count else {
return
}
self.searchBusLine(lineId: lines[time].gid)
})
let timeE:DispatchTime = DispatchTime.now() + Double(lines.count*Int(NSEC_PER_SEC)) / Double(NSEC_PER_SEC);
DispatchQueue.main.asyncAfter(deadline: timeE) {
disinterval.dispose()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment