繁体   English   中英

保持命令行工具的活力

[英]Keep command line tool alive

如何让命令行工具永远运行。

这是我的代码:

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

您需要使用CFRunLoop或NSRunLoop进入runloop。

尝试:

[[NSRunLoop currentRunLoop] run];

在Swift 4中,

RunLoop.current.run()

干杯。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM