Objective c 如何使用Objective C返回CGPoints数组

Objective c 如何使用Objective C返回CGPoints数组,objective-c,swift,Objective C,Swift,我的项目中有一个名为doWorkOnSampleBuffer的函数,它返回CGPoint的值 - (CGPoint)doWorkOnSampleBuffer:(CMSampleBufferRef)sampleBuffer inRects:(NSArray<NSValue *> *)rects { CGPoint mypoint[2]; mypoint[0] = CGPointMake(-1, -1); mypoint[1] = CGPointMake(5,

我的项目中有一个名为doWorkOnSampleBuffer的函数,它返回CGPoint的值

- (CGPoint)doWorkOnSampleBuffer:(CMSampleBufferRef)sampleBuffer inRects:(NSArray<NSValue *> *)rects {

    CGPoint mypoint[2];

    mypoint[0] = CGPointMake(-1, -1);
    mypoint[1] = CGPointMake(5, 5);

    return mypoint[1]
}
现在,我想让doWorkOnSampleBuffer函数返回CGPoint数组mypoint,而不是一个CGPoint值

那么,我如何调整我的代码来做到这一点呢?

解决了

答案是:

- (NSArray<NSValue *> *)doWorkOnSampleBuffer:(CMSampleBufferRef)sampleBuffer inRects:(NSArray<NSValue *> *)rects {

    CGPoint mypoint[2];

    mypoint[0] = CGPointMake(-1, -1);
    mypoint[1] = CGPointMake(5, 5);

    NSArray *myCGPointArray = @[[NSValue valueWithCGPoint:mypoint[0]],[NSValue valueWithCGPoint:mypoint[1]]];

    return myCGPointArray;
}
因此,您可以按如下方式访问值:

myPoint![0].cgPointValue.x
myPoint![0].cgPointValue.y
myPoint![1].cgPointValue.x
myPoint![1].cgPointValue.y
使用NSArray*是一种方法。您知道NSValue有一个使用CGPoint的初始值设定项。@哎呀,我试过:-NSArray*doWorkOnSampleBuffer:cmSampleBufferRefSampleBufferInRects:NSArray*rects{CGPoint mypoint[2];NSValue*pointArray=mypoint;mypoint[0]=CGPointMake-1,-1;mypoint[1]=CGPointMake5,5;return pointArray;}怎么了?太复杂了。Just:return@[[NSValue-valueWithCGPoint:CGPointMake-1,-1],@[[NSValue-withcgpoint:CGPointMake5,5]]
var myPoint = wrapper?.doWork(on: sampleBuffer, inRects: boundsArray)
myPoint![0].cgPointValue.x
myPoint![0].cgPointValue.y
myPoint![1].cgPointValue.x
myPoint![1].cgPointValue.y