1

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.

Richard Sun
  • 69
  • 10
  • Bridging header is not something you write manually. How is your `OpenCVWrapper` is defined? Swift class or Objective-C class? – OOPer Nov 11 '18 at 02:52
  • Sorry, I'm not sure I understand your question (I'm still new to this). I think that OpenCVWrapper is an Objective-C **interface**. I'm using the OpenCV framework, which I believe is in c++. – Richard Sun Nov 12 '18 at 01:43
  • You write Objective-C interface in combination with Objective-C implementation. The interface is needed to write the implementation, not for the bridging header. Or else when you write a Swift class, Xcode generates a bridging header. Have you written that `OpenCVWrapper` is an Objective-C class in the text of your question? – OOPer Nov 12 '18 at 11:50
  • Yes, I understand what you mean. OpenCVWrapper is an Objective-C class – Richard Sun Nov 13 '18 at 21:22

1 Answers1

1

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];
cool_jb
  • 213
  • 2
  • 9
  • Thank you, this works perfectly. Also, I've been seeing the asterisk symbol a lot in some sample code. I've read that its a pointer, whose value is actually a reference to a location. Is this correct? – Richard Sun Nov 12 '18 at 01:48
  • Yes thats correct. For more details on pointers you can go through this https://stackoverflow.com/questions/897366/how-do-pointer-to-pointers-work-in-c/897414. Also please mark the answer as accepted, so that it may help others identify the right working solution – cool_jb Nov 12 '18 at 04:38