用Object-C的时候用Dispatchsource大概是像下面这样:


#import <dispatch/dispatch.h>
#import <signal.h>
#import <stdlib.h>

int main() {
   dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL,
                                                     SIGWINCH,
                                                     0,
                                                     dispatch_get_main_queue());
   dispatch_source_set_event_handler(source, ^{
      exit(1);
   });
   dispatch_resume(source);

   dispatch_main();
}

Swiift 早期版本好像也是这样的写法。
目前Swift 5 变成了下面这样:


import Darwin
import Dispatch

let source = DispatchSource.makeSignalSource(signal: SIGWINCH, queue: .main)
source.setEventHandler {
   exit(1)
}
source.resume()

dispatchMain()

简洁了很多