I manually added two additional controllers (UINavigationControllerDelegate
& UIImagePickerController
) to a UIViewController
and I am receiving an error after adding the UIImagePickerController
that says,
Multiple inheritance from classes UIViewController and UIImagePickerController
I'm not sure how to interpret and fix that right now.
As a result of this error, I'm also seeing one when I use the image.delegate
method and set it equal to self
Type ViewController does not conform to protocol UIImagePickerControllerDelegate
Code:
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerController {
@IBAction func pickImage(sender: UIButton) {
var image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
image.allowsEditing = false
self.presentViewController(image, animated: true, completion: nil)
}
Swift doesn't allow us to declare a class with multiple base classes or superclasses, so there is no support for multiple inheritance of classes. A subclass can inherit just from one class. However, a class can conform to one or more protocols.
Multiple inheritance is not possible in Swift.
You should have UIImagePickerControllerDelegate, not UIPickerViewController in your first line. The system thinks that you are trying to have your controller inherit from both UIViewController and UIImagePickerController which is not allowed.
I think it is that swift doesn't allow multiple inheritance, protocols are essentially what other languages call interfaces and they serve the same purpose - to allow a safe and limited form of multiple inheritance. Try to change it like this. See more from here and protocol.
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With