你如何满足 Swift 中 CTFrameGetLineOrigins() 中的 'lineOrigins' 参数?
How do you satisfy the 'lineOrigins' argument in CTFrameGetLineOrigins() in Swift?
我试图从这里找出 CTFrameGetLineOrigins
:CTFrameGetLineOrigins Got Incorrect Origins,并尝试将 ObjC 转换为 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)
但是我收到 CTFrameGetLineOrigins 的第三个参数的错误:
无法将“[CGPoint]”类型的值转换为预期的参数类型'UnsafeMutablePointer'
如何克服这个错误?
你可以试试
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), UnsafeMutablePointer(&lineOrigins))
或直接
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0),&lineOrigins)
实际上我只是在参数中添加了&
,并将常量变成了变量。
let lines = CTFrameGetLines(frame)
let numOfLines: size_t = CFArrayGetCount(lines)
var lineOrigins = [CGPoint](repeating: CGPoint.zero, count: numOfLines)
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), &lineOrigins)
我试图从这里找出 CTFrameGetLineOrigins
:CTFrameGetLineOrigins Got Incorrect Origins,并尝试将 ObjC 转换为 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)
但是我收到 CTFrameGetLineOrigins 的第三个参数的错误:
无法将“[CGPoint]”类型的值转换为预期的参数类型'UnsafeMutablePointer'
如何克服这个错误?
你可以试试
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), UnsafeMutablePointer(&lineOrigins))
或直接
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0),&lineOrigins)
实际上我只是在参数中添加了&
,并将常量变成了变量。
let lines = CTFrameGetLines(frame)
let numOfLines: size_t = CFArrayGetCount(lines)
var lineOrigins = [CGPoint](repeating: CGPoint.zero, count: numOfLines)
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), &lineOrigins)