I have a protocol ImagePickerPresentable:
protocol ImagePickerPresentable {
var imagePicker: UIImagePickerController? { get set }
func presentImagePicker(withSourceType: UIImagePickerControllerSourceType) throws
func dismissImagePicker()
weak var delegate: ImagePickerPresentableDelegate? { get set }
}
I have an extension with default implementation for both functions.
extension ImagePickerPresentable where Self: UIViewController
ImagePickerPresentableDelegate:
protocol ImagePickerPresentableDelegate: class {
func imagePicker(imagePicker: UIImagePickerController, didFinishPickingImage image: UIImage?, withSuccess success: Bool)
}
I tried to extend ImagePickerPresentable for default implementation of imagePicker delegate functions:
extension ImagePickerPresentable where Self: UIImagePickerControllerDelegate & UINavigationControllerDelegate {
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissImagePicker()
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// No Callback
if let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
delegate?.imagePicker(imagePicker: picker, didFinishPickingImage: editedImage, withSuccess: true)
} else if let originalImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
delegate?.imagePicker(imagePicker: picker, didFinishPickingImage: originalImage, withSuccess: true)
} else {
delegate?.imagePicker(imagePicker: picker, didFinishPickingImage: nil, withSuccess: false)
}
}
}
In the view controller that adopts the protocol I assign self as imagePicker delegate, but ImagePickerPresentable doesn't get the callback when the imagePicker finished picking media.
If I implement the image picker delegate functions directly in the view controller, I do get the callback. I could set up a function in the protocol that handles the image picker delegate function output but is it possible to get the image picker delegate to use the default implementation of the ImagePickerPresentable delegate functions directly?
Since my View Controller conforms to ImagePickerPresentable, UIImagePickerControllerDelegate, and UINavigationControllerDelegate I thought the delegate functions in ImagePickerPresentable extension would be recognized by imagePicker delegate.