【问题标题】:Decoding HTML in Swift causes BAD_ACCESS on iOS device在 Swift 中解码 HTML 会导致 iOS 设备上的 BAD_ACCESS
【发布时间】:2015-01-07 20:39:43
【问题描述】:

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)!

你如何解决这个问题?

【问题讨论】:

    标签: html ios xcode swift decode


    【解决方案1】:

    可能您没有在主线程中运行代码。我不确定它在模拟器中是如何工作的。无论如何尝试将该代码放在主线程块中,例如 dispatch_async(dispatch_get_main_queue(), { let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil) let decodedString = attributedString?.string })

    它应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多