Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep command line tool alive

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;
}
like image 292
Tyilo Avatar asked Feb 25 '12 23:02

Tyilo


2 Answers

You need to enter into a runloop using either CFRunLoop or NSRunLoop.

Try:

[[NSRunLoop currentRunLoop] run];
like image 160
EricS Avatar answered Sep 23 '22 01:09

EricS


In Swift 4,

RunLoop.current.run()

Cheers.

like image 30
Joe Huang Avatar answered Sep 20 '22 01:09

Joe Huang