How to create a minimal daemon process in a swift 2 command line tool?
It turns out using while true
loop does block the main-thread.
Simply replace the while true
loop with NSRunLoop.mainRunLoop().run()
and you have a daemon process.
I read the sources of swifter (a swift-based server), which is doing the same.
In Swift 3 and later, the equivalent code is:
RunLoop.main.run()