Renato Pimpão
Renato Pimpão

Reputation: 271

Cannot assign a value of type '[UIImage]' to a value of type 'UIImage?'

I've created an array of UIimages inside of a structure. Now im trying to display the image and i get this error:

Cannot assign a value of type '[UIImage]' to a value of type 'UIImage?

enter image description here

"primeiraImagem.image" is an Outlet. Here is the structure: enter image description here

I'm stuck here and i cant solve this =/

Thank you :)

Upvotes: 0

Views: 5318

Answers (1)

MirekE
MirekE

Reputation: 11555

Cannot assign a value of type '[UIImage]' to a value of type 'UIImage?

restaurante.imagem is an array [UIImage]. In order to assign one image from it to an UIImage, you need to select only one image from the array. For example this code gets the first and makes sure that the assignment takes place only if the array is not empty:

if let image = restaurante.imagem.first {
    primeiraImagem.image = image
}

Upvotes: 5

Related Questions