Kirill
Kirill

Reputation: 1472

Swift 3: Expression type [UIImage] is ambiguous without more context

I try to create new array of UIImage objects:

var images = [UIImage](repeating: nil, count: 10)
for i in 0..<10
    {
        images[i] = ...
    }

But I got this error (at first row): Expression type [UIImage] is ambiguous without more context

Upvotes: 0

Views: 1590

Answers (1)

Pratik Patel
Pratik Patel

Reputation: 449

You are trying to declare an array with UIImage objects and then instantiating with nil. Try

var images = [UIImage?](repeating: nil, count: 10)

and then handle images being nil when you access them.

If you already know how you are going to populate images, you can use the map function for arrays like so:

var images = (0..<10).map { (i) -> UIImage in
    return UIImage() // however you are trying to get the UIImage
}

Upvotes: 2

Related Questions