Trap is a small Swift framework to handle operating system signals.
import Trap
let task = NSTask...
Trap.handle(.interrupt) {
task.terminate()
exit(EXIT_FAILURE)
}
task.launch()
It can also handle multiple signals at the same time.
Trap.handle(Trap.Signal.all) {
print("Signal: \($0)")
...
}
Trap is build using the stable version of Swift 3.0.