2016-01-21 83 views
0

'的參數列表調用初始值設定項我遵循本示例來解碼HTML值。 TO decode a json parsed value: answered by akashivskyy無法用類型爲'NSAttributedString'的類型爲'

我有這個代碼,我收到以下錯誤:

let encodedString = "The Weeknd ‘King Of The Fall’" 

let encodedData = encodedString.dataUsingEncoding(NSUTF8StringEncoding)! 

let attributedOptions : [String: AnyObject] = [ 
    NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, 
    NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding 
] 

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

let decodedString = attributedString.string 

錯誤:

Cannot invoke initializer for type 'NSAttributedString' with an argument list of type '(data: NSData, options: [String : AnyObject], documentAttributes: _, error: _)'

任何幫助表示讚賞建議AY答案。

回答

2

取下NSAttributedString初始化的error選項,並添加try代替:

let attributedString = try? NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) 
+0

我認爲錯誤是包括在最新的雨燕2.1的異常處理代碼。 – Danboz

+0

對!我忘了試試。 – null

相關問題