user2167323
user2167323

Reputation: 159

Cannot call value of non-function type 'UIImage?'

I am trying to run this code that will randomise a UIImage. But I am getting the following error Cannot 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's a draw!")
    }       
}

I am also getting the error Cannot call value of non-function type 'String?' for the resultLabel.text. Any help would be much appreciated.

Upvotes: 4

Views: 3712

Answers (1)

veducm
veducm

Reputation: 5953

To set the property image of an existing UIImageView, you need to assign it a new instance of UIImage:

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

Same thing for the text of a UILabel:

resultLabel.text = "It's a draw!"

Upvotes: 2

Related Questions