Last active
March 17, 2017 18:27
-
-
Save VojtaStavik/5262141f98100637024d to your computer and use it in GitHub Desktop.
Keeps the main loop running for swift scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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