15

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;
}
Tyilo
  • 28,998
  • 40
  • 113
  • 198

2 Answers2

25

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

Try:

[[NSRunLoop currentRunLoop] run];
EricS
  • 9,650
  • 2
  • 38
  • 34
4

In Swift 4,

RunLoop.current.run()

Cheers.

Joe Huang
  • 6,296
  • 7
  • 48
  • 81