我正在尝试从这里CTFrameGetLineOrigins Got Incorrect Origins中找出CTFrameGetLineOrigins
,并尝试将ObjC转换为Swift。
Obj-C:
CFArrayRef lines = CTFrameGetLines(frame);
size_t numOfLines = CFArrayGetCount(lines);
CGPoint lineOrigins[numOfLines];
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins);
迅速:
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”
如何克服此错误?
答案 0 :(得分:2)
实际上,我只是将var arr = [{a:1, b:2, c:3, d:4}, {a:1, x:2, y:3, z:4}, {a:1, x:2, y:3, z:4}];
let result = arr.every((obj)=> obj.a === 1);
console.log(result);//true
arr = [{a:1, b:2, c:3, d:4}, {a:1, x:2, y:3, z:4}, {a:2, x:2, y:3, z:4}];
result = arr.every((obj)=> obj.a === 1);
console.log(result);//false
//Checks whether all the a keys is same in the array of objects.
result = arr.every((obj)=> obj.a === arr[0].a);
console.log(result); //false
arr = [{a:1, b:2, c:3, d:4}, {a:1, x:2, y:3, z:4}, {a:1, x:2, y:3, z:4}];
result = arr.every((obj)=> obj.a === arr[0].a);
console.log(result); //true
添加到参数中,并将常量设为变量。
&
答案 1 :(得分:1)
您可以尝试
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), UnsafeMutablePointer(&lineOrigins))
或直接
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0),&lineOrigins)