mosaic6
mosaic6

Reputation: 933

Cannot convert value of type '[String : AnyObject]?.Type' (aka 'Optional<Dictionary<String, AnyObject>>.Type) to expected argument type

Getting this error on size = text.boundingRectWithSize

Cannot convert value of type '[String : AnyObject]?.Type' (aka 'Optional>.Type) to expected argument type '[String : AnyObject]?'

func heightOfString(text: NSString!, width: CGFloat, font: UIFont) -> CGFloat{
    var ch:CGFloat!
    var size:CGSize = CGSizeMake(width, CGFloat.max)

    var tdic:NSDictionary = NSDictionary(objects: [font, NSFontAttributeName], forKeys: [])
    size = text.boundingRectWithSize(size, options: NSStringDrawingOptions.UsesFontLeading , attributes: [String : AnyObject]?, context: nil).size
    ch = size.height
    return ch

}

Upvotes: 1

Views: 4608

Answers (1)

Eric Aya
Eric Aya

Reputation: 70097

If you need to pass an empty dictionary for the attributes, use [:]

size = text.boundingRectWithSize(size, options: NSStringDrawingOptions.UsesFontLeading , attributes: [:], context: nil).size

Upvotes: 2

Related Questions