Skip to content

Instantly share code, notes, and snippets.

@VojtaStavik
Last active March 17, 2017 18:27
Show Gist options
  • Save VojtaStavik/5262141f98100637024d to your computer and use it in GitHub Desktop.
Save VojtaStavik/5262141f98100637024d to your computer and use it in GitHub Desktop.
Keeps the main loop running for swift scripts
class MainProcess {
var shouldExit = false
func start () {
// do your stuff here
// set shouldExit to true when you're done
}
}
var runLoop : NSRunLoop
var process : MainProcess
autoreleasepool {
runLoop = NSRunLoop.currentRunLoop()
process = MainProcess()
process.start()
while (!process.shouldExit && (runLoop.runMode(NSDefaultRunLoopMode, beforeDate: NSDate(timeIntervalSinceNow: 2)))) {
// do nothing
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment