Skip to content

Instantly share code, notes, and snippets.

@syzdek
Created July 31, 2012 21:36
Show Gist options
  • Save syzdek/3220789 to your computer and use it in GitHub Desktop.
Save syzdek/3220789 to your computer and use it in GitHub Desktop.
Creating an NSRunLoop for a command line utility.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSRunLoop * runLoop;
CLIMain * main; // replace with desired class
@autoreleasepool
{
// create run loop
runLoop = [NSRunLoop currentRunLoop];
main = [[CLIMain alloc] init]; // replace with init method
// kick off object, if required
[main start];
// enter run loop
while((!(main.shouldExit)) && (([runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:2]])));
};
return(main.exitCode);
}
@trojanfoe
Copy link

Please see the following for a object-oriented approach: https://github.com/trojanfoe/RunLoopController

@heberth2788
Copy link

beautiful code !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment