Dirder Dirder - 7 months ago 489
Swift Question

How to resolve "Type of expression in ambiguous without more context"?

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


Compiler error: "Type of expression in ambiguous without more context"
How could it be solved?

Answer

required [String : AnyObject]format required by attributedOptions parameter

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)")
    }