Skip to content

Instantly share code, notes, and snippets.

@Krishna
Forked from syzdek/cli-nsrunloop.m
Created June 13, 2018 08:20
Show Gist options
  • Save Krishna/64b0f7e354b1f42a49026761d057278b to your computer and use it in GitHub Desktop.
Save Krishna/64b0f7e354b1f42a49026761d057278b 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment