I have the following code working in Objective-C
NSArray *lines = (NSArray *)CTFrameGetLines((__bridge CTFrameRef)columnFrame);
CGPoint origins[[lines count]];
CTFrameGetLineOrigins((__bridge CTFrameRef)columnFrame, CFRangeMake(0, 0), origins);
But when ported to Swift, the compiler complains with a Cannot convert the expression′s ′Void′to type ′CMutablePointer<CGPoint>
in the CTFrameGetLineOrigins
line
let nsLinesArray: NSArray = CTFrameGetLines(ctFrame) // Use NSArray to bridge to Array
let ctLinesArray = nsLinesArray as Array
var originsArray: Array<CGPoint> = CGPoint[]()
//var originsArray: NSMutableArray = NSMutableArray.array()
let range: CFRange = CFRangeMake(0, 0)
CTFrameGetLineOrigins(ctFrame, range, originsArray)
I had to use NSArray in the CGFrameGetLines
function, and then convert to a Swift Array, and inspecting the ctLinesArray, shows that the CTLine
objects are retrieved correctly
I tried using NSMutableArray
for the originsArray, with the same result.
Any idea of what is missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…