2016-05-07 1 views
2
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)! 

コンパイラエラー:「文脈のないあいまいな式の種類」 どのように解決できますか? SWIFT 2.0+でattributedOptionsパラメータ"コンテキストがなくてもあいまいではない式のタイプ"を解決するには?

do { 
     let encodedData = yourEncodedString.dataUsingEncoding(NSUTF8StringEncoding)! 
     let attributedOptions : [String: AnyObject] = [ 
      NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, 
      NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding 
     ] 
     let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) 
     // self.init(attributedString.string) 
    } catch { 
     fatalError("Unhandled error: \(error)") 
    } 

答えて

5

必要[String : AnyObject]フォーマットは、エラーパラメータは、呼から削除すべきです。コンパイラは私にとって誤解を招いていました。

ので、代わりの:

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

用途:

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

感謝!それは助けになった – Dirder

3

によって必要

関連する問題