【问题标题】:Keep command line tool alive保持命令行工具活着
【发布时间】:2012-02-25 23:38:00
【问题描述】:

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

这是我的代码:

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

【问题讨论】:

    标签: objective-c command-line-tool


    【解决方案1】:

    您需要使用 CFRunLoop 或 NSRunLoop 进入运行循环。

    试试:

    [[NSRunLoop currentRunLoop] run];
    

    【讨论】:

    • 它应该是NSRunLoop,带有大写 L,否则效果很好。
    【解决方案2】:

    在 Swift 4 中,

    RunLoop.current.run()
    

    干杯。

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 2018-05-10
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 1970-01-01
      相关资源
      最近更新 更多