SwiftUI 在 iOS 17 上发生“诡异”崩溃的解决:AsyncRenderer layout engine performed from background thread

在这里插入图片描述

问题现象

在系统升级到 iOS 17 后,原本正常的 SwiftUI 代码在运行时突然发生崩溃,提示如下信息:

com.apple.SwiftUI.AsyncRenderer (17): “Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.”
在这里插入图片描述

这是怎么回事呢?

通过上面出错信息,大家可能认为这只是一个常见的“从后台线程更改界面”的错误,但其实它绝没这么简单。因为从 App 中压根找不到后台线程对界面“指手画脚”的任何代码!

它实际和 iOS 17 中一个重大更新有着千丝万缕的关系!

闲言少叙,Let‘s fix it!!!😉


问题分析

1. 抽丝剥茧

在检查源代码之前,让我们先来仔细分析一下这个“奇怪的”崩溃:

  • 首先,崩溃位置是在一个名为 com.apple.SwiftUI.AsyncRenderer 的陌生线程中:

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-05 21:52:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-05 21:52:03       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-05 21:52:03       82 阅读
  4. Python语言-面向对象

    2023-12-05 21:52:03       91 阅读

热门阅读

  1. sklearn教程:iris鸢尾花数据集数据分析

    2023-12-05 21:52:03       54 阅读
  2. 爬虫中XPath语法四个重要概念及示例

    2023-12-05 21:52:03       61 阅读
  3. 微信小程序:input双向绑定

    2023-12-05 21:52:03       56 阅读
  4. 【Qt之QColor】

    2023-12-05 21:52:03       52 阅读
  5. 逻辑回归 正则化

    2023-12-05 21:52:03       54 阅读