How do you satisfy the 'lineOrigins' argument in CTFrameGetLineOrigins() in Swift? [duplicate]

一曲冷凌霜 提交于 2019-12-23 04:12:36

问题


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?


回答1:


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)



回答2:


You can try

CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), UnsafeMutablePointer(&lineOrigins))

or directly

CTFrameGetLineOrigins(frame, CFRangeMake(0, 0),&lineOrigins)


来源:https://stackoverflow.com/questions/52320155/how-do-you-satisfy-the-lineorigins-argument-in-ctframegetlineorigins-in-swif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!