Unable to call non-function value 'UIImage?'

I am trying to run this code, which will be random UIImage. But I get the following errorCannot call value of non-function type 'UIImage?

@IBOutlet weak var resultLabel: UILabel!
@IBOutlet weak var PersonsChoice: UIImageView!
var option = ["rock.png", "paper.png", "scissors.png"]

func chooseWinner(userChoice:Int){
    let randomNumber = Int(arc4random_uniform(3))
    PersonsChoice.image(option[randomNumber])

    if (randomNumber == 0 && userChoice == 1)
        || (randomNumber == 1 && userChoice == 2)
        || (randomNumber == 2 && userChoice == 0) {        
        resultLabel.text("You Win")
    } else if (userChoice == 0 && randomNumber == 1)
        || (userChoice == 1 && randomNumber == 2)
        || (userChoice == 2 && randomNumber == 0) {
        resultLabel.text("I Win!")
    } else {
        resultLabel.text("It a draw!")
    }       
}

I also get an error Cannot call value of non-function type 'String?' for resultLabel.text. Any help would be greatly appreciated.

+4
source share
1 answer

To set a property of an imageexisting one UIImageView, you need to assign it a new instance UIImage:

PersonsChoice.image = UIImage(named: option[randomNumber])

The same goes textfor UILabel:

resultLabel.text = "It a draw!"
+3
source

Source: https://habr.com/ru/post/1617853/


All Articles