【发布时间】:2023-03-04 21:11:01
【问题描述】:
Xcode 7.3 和 Swift 2.2
在一个 swift 文件中,我有一个字符串扩展,可以将 HTML 文本转换为 NSAttributedString。
extension String {
func htmlAttributedString() -> NSAttributedString? {
guard let data = self.dataUsingEncoding(NSUTF16StringEncoding, allowLossyConversion: false) else { return nil }
guard let html = try? NSMutableAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) else { return nil }
return html
}
}
我就是这样用的。
let HTMLstr = "<p><b>hello</b> world</p>"
if let attrString = HTMLstr.htmlAttributedString() {
// do something here
}
它在我的手机和模拟器上运行良好,但是当我归档它时,它会在使用上面的代码时导致崩溃。我认为问题在于dataUsingEncoding。任何想法为什么在使用归档应用程序时会崩溃。
编辑
我已包含崩溃日志的标题:
Incident Identifier: 90C74E49-4C65-4556-B82D-6748437BB5BA
CrashReporter Key: 4fb0e685f950c6cdecf7132b26f38ff54e013348
Hardware Model: iPhone7,1
Process: AppName [7813]
Path: /private/var/containers/Bundle/Application/1EE7C00E-7600-4D72-839D-8AEA834903B8/AppName.app/AppName
Identifier: uk.co.skymook.AppName
Version: 1 (2.0)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2016-08-13 12:16:08.08 +0100
Launch Time: 2016-08-13 12:15:33.33 +0100
OS Version: iOS 9.3.2 (13F69)
Report Version: 105
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x2000000000000000
Triggered by Thread: 0
Filtered syslog:
None found
【问题讨论】:
-
你能把错误贴在这里吗?
标签: ios swift crash nsattributedstring