的Xcode 7.3和雨燕2.2崩溃的HTML字符串转换时NSAttributedString
在迅速的文件运行存档我有一个字符串extention是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
你可以在这里粘贴错误吗? –