Hit NSAttributedString: "The type of an expression is ambiguous without additional context"

Can someone tell me what happened?

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

Mistake:

The type of expression is ambiguous without additional context.

This happened after insertion. NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle

+4
source share
1 answer

Try the following:

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:)expects a type dictionary [String: AnyObject]. However, m StyleSingleis Int. Therefore, you must wrap it inside NSNumber.

+8
source

Source: https://habr.com/ru/post/1609396/


All Articles