I am trying to convert the following Objective-C code ( source ) from this
-(CGRect) dimensionsForAttributedString: (NSAttributedString *) asp {
CGFloat ascent = 0, descent = 0, width = 0;
CTLineRef line = CTLineCreateWithAttributedString( (CFAttributedStringRef) asp);
width = CTLineGetTypographicBounds( line, &ascent, &descent, NULL );
}
in Swift:
func dimensionsForAttributedString(asp: NSAttributedString) -> CGRect {
let ascent: CGFloat = 0
let descent: CGFloat = 0
var width: CGFloat = 0
let line: CTLineRef = CTLineCreateWithAttributedString(asp)
width = CTLineGetTypographicBounds(line, &ascent, &descent, nil)
}
But I get an error with &ascentin this line:
width = CTLineGetTypographicBounds(line, &ascent, &descent, nil)
'&' is used with a non-inout argument of type UnsafeMutablePointer
Xcode suggests fixing the error by deleting &. When I do this, I get an error
Cannot convert value of type 'CGFloat' to the expected argument type 'UnsafeMutablePointer'
Interacting with API documentation The C API uses syntax &, so I donβt understand what the problem is. How to fix this error?