-(CGPoint*)func
{
CGPoint* result = calloc(2, sizeof(CGPoint));
result[0] = ..;
result[1] = ..;
return result;
}
how cast this array to swift [CGPoint] ?
You can use UnsafeBufferPointer to cast it as follows
let pointer: UnsafeMutablePointer<CGPoint> = yourInstance.func()
let swiftArray = Array(UnsafeBufferPointer(start: pointer, count: 2))
free(pointer)
EDIT
If you really need to use C arrays, you may want to rewrite the func method to something like:
- (CGPoint*)pointArray:(NSInteger *)length
{
int arrSize = 2;
CGPoint* result = calloc(arrSize, sizeof(CGPoint));
result[0] = ...
result[1] = ...
*length = arrSize;
return result;
}
Then on the Swift side:
var arrayLength: Int = 0
let pointer: UnsafeMutablePointer<CGPoint> = yourInstance.pointArray(&arrayLength)
let swiftArray = Array(UnsafeBufferPointer(start: pointer, count: arrayLength))
free(pointer)