的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
你可以在這裏粘貼錯誤嗎? –