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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With