Jakob Hansen Jakob Hansen - 1 year ago 188
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 Source

Wrong kind of bracket:

return images(randomImage)

Replace that line with:

return images[randomImage]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download