noobdev noobdev - 7 months ago 131
Ruby Question

Swift 1.2 to swift 2: Objective C method conflicts with optional requirement method

I'm trying to develop an app that accesses the phone's camera based on a tutorial I found online (https://www.raywenderlich.com/85528/user-accounts-ios-ruby-rails-swift#next_section). However my camera extension at the imagePickerController function keeps throwing up this error:


Objective-C method '
imagePickerController: didFinishPickingMediaWithInfo:
' provided by method '
imagePickerController(_:didFinishPickingMediaWithInfo:)
' conflicts with optional requirement method
imagePickerController(_:didFinishPickingMediaWithInfo:)



This is the code where the error was thrown

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {}


The affected code block is as shown below

// Camera Extension
extension SelfieCollectionViewController : UINavigationControllerDelegate, UIImagePickerControllerDelegate {
func displayCameraControl() {
var imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera

if UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front) {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Front
} else {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Rear
}
} else {
imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
}

self.presentViewController(imagePickerController, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
}
}


The full code block can be found here (https://codeshare.io/UurWD) at line 111.

Answer

replace

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { }

with

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { }