-1

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?

Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • @matt That's why we're asking. :) First, Patrick suggests posting on SO with questions tagged with "pbjvision." Also, since we're new to Swift and iOS, we didn't know if we were doing something wrong. Someone else already reported the problem, and Patrick merged a fix ... but what you're saying is we are doing this properly? Why is the error happening? We're able to use other delegate methods. – Crashalot Jun 20 '15 at 04:02
  • @matt can you explain why this is happening? Our ViewController is a delegate conforming to the PBJVision protocol. Isn't our function signature supposed to match the function signature defined by the protocol -- that's the confusion around the error. – Crashalot Jun 20 '15 at 22:11

1 Answers1

1

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?) {
    // ...
}
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Wow, that worked. Thanks! But why did you use [NSObject : AnyObject]? instead of NSDictionary? since NSDictionary is nullable and referenced in the Obj-C declaration? – Crashalot Jun 20 '15 at 22:39