How would a keep a command-line tool running for ever.
This is my code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *notification)
{
NSLog(@"%@", notification);
}];
//Keep alive...
}
return 0;
}
You need to enter into a runloop using either CFRunLoop or NSRunLoop.
Try:
[[NSRunLoop currentRunLoop] run];
In Swift 4,
RunLoop.current.run()
Cheers.
来源:https://stackoverflow.com/questions/9449123/keep-command-line-tool-alive