Bridging Header Method Parameter Issue

233 Views Asked by At

I'm trying to learn how to use Bridging Headers in this test project. For this part, I want to have a method where it takes in and returns a CGPoint array.

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import <CoreGraphics/CoreGraphics.h>

    @interface OpenCVWrapper : NSObject

    + (UIImage *)grayscaleImage:(UIImage *)image;
    + (UIImage *)gaussianBlurImage:(UIImage *)image;
    + (UIImage *)cannyEdgeImage:(UIImage *)image;

    //Error says Expected a type
    + ([CGPoint *])lineEdges:([CGPoint *])points;

    @end

Because I'm new to this, I don't know where to even start looking for a problem.

1

There are 1 best solutions below

2
On BEST ANSWER

Since you need to return an array of CGPoint, your array should hold a NSValue type, because the array cannot hold struct type

+ (NSArray<NSValue *> *)lineEdges:(NSArray<NSValue *> *)points;

and you should call your method as

NSArray *lineEdges = [OpenCVWrapper lineEdges:@[[NSValue valueWithCGPoint:CGPointMake(3.3, 4.4)]]];

The return value also should be in NSValue and extracting

NSValue *val = [lineEdges objectAtIndex:0];
CGPoint p = [val CGPointValue];