gpt4 book ai didi

swift - 在 Swift 4 中处理 SIGPIPE

转载 作者:行者123 更新时间:2023-11-30 10:48:43 25 4
gpt4 key购买 nike

我正在尝试将 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
}

我收到错误:

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

最佳答案

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
}

关于swift - 在 Swift 4 中处理 SIGPIPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55132842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com