Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Can anybody tell me what's wrong ?

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

The error is:

Type of expression is ambiguous without more context

This happened after inserting NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle

like image 993
GIJOW Avatar asked Sep 29 '15 00:09

GIJOW


1 Answers

Try this:

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 dictionary of type [String: AnyObject]. Howeverm StyleSingle is an Int. Hence you must wrap it inside an NSNumber.

like image 115
Code Different Avatar answered Oct 19 '22 17:10

Code Different