Skip to content

Instantly share code, notes, and snippets.

@zafarivaev
Created June 14, 2020 11:44
Show Gist options
  • Save zafarivaev/e4b8b473b9b971c656a25af580016670 to your computer and use it in GitHub Desktop.
Save zafarivaev/e4b8b473b9b971c656a25af580016670 to your computer and use it in GitHub Desktop.
import Foundation
import Combine
var subscriptions = Set<AnyCancellable>()
let start = Date()
Timer.publish(every: 1.0, on: .main, in: .common)
.autoconnect()
.map({ (output) in
return output.timeIntervalSince(start)
})
.map({ (timeInterval) in
return Int(timeInterval)
})
.sink { (seconds) in
print("Seconds: \(seconds)")
}
.store(in: &subscriptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment