0

I am trying to port over my Obj-C code to a Swift project and am having difficulties compiling the SIGPIPE handler:

func SigPipeHandler()
{
  print(@"We Got a Pipe Single :%d____________",s);
}


func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    signal(SIGPIPE, SigPipeHandler);
    // Override point for customization after application launch.
    return true
}

I am getting the error:

Cannot convert value of type '() -> ()' to expected argument type '(@convention(c) (Int32) -> Void)?'

George L
  • 1,673
  • 2
  • 26
  • 39
  • 1
    [Swift command line tool exit callback](https://stackoverflow.com/q/42646857) | [Trap sigint in Cocoa macOS application](https://stackoverflow.com/q/50225548) – jscs Mar 13 '19 at 01:03

1 Answers1

1
let handler: @convention(c) (Int32) -> () = { sig in
    // handle the signal somehow
    print("error", sig)
}


func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    signal(SIGPIPE, handler);
    // Override point for customization after application launch.
    return true
}
George L
  • 1,673
  • 2
  • 26
  • 39