gpt4 book ai didi

objective-c - 我如何刷新 NSLog 的缓冲区?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:53 24 4
gpt4 key购买 nike

我有这样的错误处理代码:

if (ERROR) {
NSLog(@"<some message>");
exit(-1);
}

使用 NSLog 记录的消息并不总是出现在控制台中,大概是因为 exit() 终止了进程而不刷新 NSLog 的缓冲区。我如何自己刷新 NSLog 的缓冲区?

最佳答案

尝试以下操作:

if (ERROR) {
NSLog(@"<some message>");
fflush(stderr);
exit(-1);
}

但是你不应该在生产代码中使用exit因为Apple Human Interface Guidelines说清楚:

Never quit an iOS application programmatically because people tend to interpret this as a crash. However, if external circumstances prevent your application from functioning as intended, you need to tell your users about the situation and explain what they can do about it. Depending on how severe the application malfunction is, you have two choices.

关于objective-c - 我如何刷新 NSLog 的缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9546742/

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