The solution to user Timer.publish() in a Command Line Tool app could be to use RunLoop. But I can figure out how.
If I write the following it doesn’t work more than if I don’t use RunLoop.
RunLoop.current.run()
let subscription = Timer.publish(every: 1.0, on: .main, in: .default)
.autoconnect()
.sink { _ in
print("timer fired")
}
2
Answers
The solution given by Ole Begemann on swift forums. Thx to him.
It seams "withExtendedLifetime(x:,body:)" is needed to avoid compiler to destroy the subscription instance before the RunLoop start.
The problem is merely that you are giving the commands in the wrong order. Try it like this: