如何解决"在没有更多背景的情况下模糊的表达类型"?

时间:2016-05-07 11:21:38

标签: ios swift compiler-errors

Host: smtp.gmail.com
Port: 587
Encryption: Force TLS
Auth Method: Login
username: someuser@gmail.com
password: mypass

编译器错误:"不含更多上下文的模糊表达类型" 怎么可以解决?

2 个答案:

答案 0 :(得分:5)

attributionOptions参数

所需的[String : AnyObject]格式
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)")
    }

答案 1 :(得分:3)

在swift 2.0+中,应该从调用中删除错误参数。编译器误导了我。

所以而不是:

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

使用:

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