Example (Apple Official)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | let df = DateFormatter () df . dateStyle = . none df . timeStyle = . long cancellable = Timer . publish ( every : 1.0 , on : . main , in : . default ) . autoconnect () . handleEvents ( receiveOutput : { date in print ( "Sending Timestamp \'\( df . string ( from : date ) )\' to delay()" ) }) . delay ( for : . seconds ( 3 ), scheduler : RunLoop . main , options : . none ) . sink ( receiveCompletion : { print ( "completion: \( $ 0 )" , terminator : "\n" ) }, receiveValue : { value in let now = Date () print ( "At \( df . string ( from : now ) ) received Timestamp \'\( df . string ( from : value ) )\' sent: \( String ( format : "%.2f ", now.timeIntervalSince(value))) secs ago" , terminator : "\n" ) } ) |