Reputation: 61
I have a function in my project called doWorkOnSampleBuffer that returns a value of 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]
}
This function is called inside another swift file as follow:
var myPoint = wrapper?.doWork(on: sampleBuffer, inRects: boundsArray)
Now, I would like to make the doWorkOnSampleBuffer function return the CGPoint array "mypoint", instead of just one CGPoint value.
So, how can I adapt my code to do that?
Upvotes: 0
Views: 722
Reputation: 61
Solved!
The answer is:
- (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;
}
Now, if you call this function like:
var myPoint = wrapper?.doWork(on: sampleBuffer, inRects: boundsArray)
So you can access values as follows:
myPoint![0].cgPointValue.x
myPoint![0].cgPointValue.y
myPoint![1].cgPointValue.x
myPoint![1].cgPointValue.y
Upvotes: 1