I'm trying to figure out CTFrameGetLineOrigins
from here: CTFrameGetLineOrigins Got Incorrect Origins, and trying to convert the ObjC to Swift.
Obj-C:
CFArrayRef lines = CTFrameGetLines(frame);
size_t numOfLines = CFArrayGetCount(lines);
CGPoint lineOrigins[numOfLines];
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins);
Swift:
let lines = CTFrameGetLines(frame)
let numOfLines: size_t = CFArrayGetCount(lines)
let lineOrigins = [CGPoint](repeating: CGPoint.zero, count: numOfLines)
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins)
But I am getting an error for the 3rd parameter of CTFrameGetLineOrigins:
Cannot convert value of type '[CGPoint]' to expected argument type 'UnsafeMutablePointer'
How do I get past this error?
Actually I just added &
to the parameter and made the constant a variable.
let lines = CTFrameGetLines(frame)
let numOfLines: size_t = CFArrayGetCount(lines)
var lineOrigins = [CGPoint](repeating: CGPoint.zero, count: numOfLines)
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), &lineOrigins)