Search code examples
swiftxcodeuiimageviewswitch-statementuiimage

Cannot assign value of type 'UIImage' to type 'UIImageView'


I am making a simple Personality Quiz where based on the results it will display a certain image into the ImageView on my Main Storyboard. In QuestionData.Swift I have used the following switch statement:

var image: UIImage { //personality image
   switch self { //Checking what answer it matches to
   case .open: return UIImage(named: "football.jpg")!
   case .conscience: return UIImage(named: "football.jpg")!
   case .extra: return UIImage(named: "football.jpg")!
   case .agree: return UIImage(named: "football.jpg")!
   case .neuro: return UIImage(named: "football.png")! //for testing purposes all images are the same
    }

}

In my ResultsViewController:

 @IBOutlet weak var resultsImage: UIImageView!

//function code goes here

            resultsImage = mostCommonAnswer.image //matches image to personality result

I get the error 'Cannot assign value of type 'UIImage' to type 'UIImageView''

Any ideas how to fix this?


Solution

  • You need to set your image to UIImage property of UIImageView

    resultsImage.image = mostCommonAnswer.image