通过 NSAttributedString 删除:"Type of expression is ambiguous without more context"

Strike through NSAttributedString: "Type of expression is ambiguous without more context"

谁能告诉我怎么了?

let myTitle = NSAttributedString(string: Xdevices[row].deviceName!,
              attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 
              15.0)!,NSForegroundColorAttributeName:UIColor.orangeColor(), 
              NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle])

错误是:

Type of expression is ambiguous without more context

这发生在插入 NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle

之后

试试这个:

let attributes = [
    NSFontAttributeName: UIFont(name: "Georgia", size: 15.0)!,
    NSForegroundColorAttributeName: UIColor.orangeColor(),
    NSStrikethroughStyleAttributeName: NSNumber(integer: NSUnderlineStyle.StyleSingle.rawValue)
]

let myTitle = NSAttributedString(string: Xdevices[row].deviceName!, attributes: attributes)

NSAttributedString(string:attributes:) 需要 [String: AnyObject] 类型的字典。但是m StyleSingle 是一个Int。因此,您必须将其包装在 NSNumber.