Home > Back-end >  I've tried Everything -> Cannot assign value of type '[UIImage]' to type 'UII
I've tried Everything -> Cannot assign value of type '[UIImage]' to type 'UII

Time:08-18

I'm a new developer and I've tried to see documentation but I can't quite get a simple explanation.

I have this line of code:

import UIKit

class ViewController: UIViewController {

   
    @IBOutlet var GoToSettings: UITabBarItem!
    @IBOutlet weak var dogFact1: UIImageView!
    
    var onlyImageView = 1

    @IBAction func nextFactGo(_ sender: Any) {
        
        
        print("NextFactRequested")
        
        dogFact1.image = [ //uploadedimage, //uploadedimage, //uploadedimage] [Int.random(in: 0...3)]
        onlyImageView  = onlyImageView   1
        //image is second in view
    }
    
    
    }
weak var tavbarvar: UITabBar!

Note i've changed the actual image into //uploadedimage to make code snippet shorter

I attain an error at: dogFact1.image = [etc...]

I tried this previously and it worked...

I'd be really grateful if you could edit the code so that it would work an explanation would be out of this world!

TYSM

CodePudding user response:

Error it self explains what the issue is.

Cannot assign value of type '[UIImage]' to type 'UIImage' means your variable is expecting a value of type UIImage. But u are assigning a value of type[UIImage](an array of UIImage).

So instead of dogFact1.image = [ //uploadedimage, //uploadedimage, //uploadedimage] use dogFact1.image = uploadedimage.

CodePudding user response:

youre assigning an image array to an image.

  • Related