swift - 在 Swift 4 中处理 SIGPIPE
问题描述
我正在尝试将我的 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)-> 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
}
推荐阅读
- javascript - 是否可以在 javascript 中读取预检请求
- javascript - 如何在 FIREBASE WEB javascript 中为用户创建特定的 URI
- reactjs - 样式化的组件不应用样式
- java - 如何自定义 OnDraw() 的使用
- python - 您可以在列表中创建一个变量然后调用它吗?
- mysql - 在 Laravel 中使用 2 个数据库的咨询
- python - Tensorflow对象检测:如何计算边界框与框架中指定区域之间的距离
- flutter - 颤振错误:I/时间线(16820):时间线:Activity_launch_request 时间:54370667 意图:意图 { act=android.media.action.IMAGE_CAPTURE
- java - 使用杰克逊通过json文件的键选择值
- python - AttributeError: module 'selenium.webdriver' has no attribute 'Chrome' error using ChromeDriver and Chrome through Selenium