Error bridging Obj-C code and Swift: method "U" provided by method "Z" conflicts with optional requirement method "X" in protocol "Y"

116 views Asked by At

The goal is to incorporate PBJVision, an Objective-C library for capturing photos and videos, into a Swift app.

Unfortunately, we are seeing this error:

Objective-C method 'vision:capturedVideo:error:' provided by method 'vision(:capturedVideo:error:)' conflicts with optional requirement method 'vision(:capturedVideo:error:)' in protocol 'PBJVisionDelegate'

Here's the delegate method triggering the error:

func vision(vision: PBJVision, capturedVideo: NSDictionary, error: NSError) {
    println("Encountered error during recording \(error)")
    println("Captured video")
}

It seems like the problem was patched a while ago, but we are on the new version (i.e., changes mentioned are already incorporated) and still seeing the error.

Why is this happening, and how can we fix this?

1

There are 1 answers

1
matt On BEST ANSWER

It's simply a matter of translating Objective-C into Swift. The Objective-C declaration looks like this:

- (void)vision:(PBJVision *)vision capturedPhoto:(nullable NSDictionary *)photoDict error:(nullable NSError *)error;

Therefore, to match it, your declaration should look like this:

func vision(vision: PBJVision, capturedVideo videoDict: [NSObject : AnyObject]?, error: NSError?) {
    // ...
}