我试图将我的Obj-C代码移植到Swift项目,并且在编译SIGPIPE处理程序时遇到困难:
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
}
我遇到了错误:
无法将类型'()->()'的值转换为预期的参数类型 ``((@convention(c)(Int32)->虚空)?'
答案 0 :(得分:0)
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
}