Keep command line tool alive

一世执手 提交于 2020-01-12 03:27:27

问题


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;
}

回答1:


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

Try:

[[NSRunLoop currentRunLoop] run];



回答2:


In Swift 4,

RunLoop.current.run()

Cheers.



来源:https://stackoverflow.com/questions/9449123/keep-command-line-tool-alive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!