gpt4 book ai didi

html - 在 Swift 中解码 HTML 会在 iOS 设备上导致 BAD_ACCESS

转载 作者:行者123 更新时间:2023-11-28 07:14:36 25 4
gpt4 key购买 nike

遵循 How do I decode HTML entities in swift? 的伟大示例我设法解码了一个 HTML 实体。但是,在 iOS 模拟器中运行我的应用程序不会导致错误,而在真实设备上进行测试时会出现错误。

我收到以下错误:

Thread 1: EXC_BAD_ACCESS (code=1, address=0xc)

在这一行:

let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)!

你是如何解决这个问题的?

最佳答案

可能您没有在主线程中运行代码。我不确定它在模拟器中是如何工作的。无论如何尝试将该代码放在主线程 block 中 dispatch_async(dispatch_get_main_queue(),
{
让 attributedString = NSAttributedString(数据:encodedData,选项:attributedOptions,documentAttributes:无,错误:无)
让 decodedString = attributedString?.string
})

它应该可以正常工作。

关于html - 在 Swift 中解码 HTML 会在 iOS 设备上导致 BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26862505/

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