Reputation: 171
I'm trying to write some code, but I get the error in the title... here is the code...
let text: NSString = messages[indexPath.row] as! NSString
var size: CGSize = text.boundingRectWithSize(CGSizeMake(240.0, 480.0), options: NSStringDrawingOptions.UsesDeviceMetrics, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14.0)], context: nil)
I get the error in the second line
Also, I have the Objective-C code, which is ok... But I'd like it in Swift
NSString *text = [messages objectAtIndex:indexPath.row];
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0f, 480.0f) lineBreakMode:UILineBreakModeWordWrap];
Thanks in advance!!!
Upvotes: 1
Views: 2998
Reputation: 5787
Try adding .size
to the end like:
var size:CGSize = text.boundingRectWithSize(CGSizeMake(240.0, 480.0), options: NSStringDrawingOptions.UsesDeviceMetrics, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14.0)], context: nil).size
Upvotes: 6