Jakob Hansen Jakob Hansen - 5 months ago 59
Swift Question

cannot call value of non-function type '[UIImage]

I'm trying to create an array of images and a method which will allow me to generate a random image.

I've read another question on here, but it didn't really solve my problem, could anyone try to explain to me what's going on here, not just give me the answer.

import GameplayKit
import UIKit


struct ImgArray {
let images = [
UIImage(named: "emoji01.png")!,
UIImage(named: "emoji02.png")!,
UIImage(named: "emoji03.png")!,
UIImage(named: "emoji04.png")!,
UIImage(named: "emoji05.png")!
]

func getRandomImage() {
let randomImage = GKRandomSource.sharedRandom().nextIntWithUpperBound(images.count)
return images(randomImage)
}

}

Answer

Wrong kind of bracket:

return images(randomImage)

Replace that line with:

return images[randomImage]
Comments