"Cannot invoke 'insert' with an argument list of type" on a compressed image

622 Views Asked by At

Im getting this error and don't know why 'Cannot invoke 'insert' with an argument list of type '(Character, atIndex: Int)''

This code its working:

firstImageView.contentMode = .ScaleAspectFit

let imageData = UIImageJPEGRepresentation(pickedImage,0.75)

restaurante.imagem.insert(pickedImage, atIndex: imagemEscolhida-1)

This one is not:

firstImageView.contentMode = .ScaleAspectFit

let imageData = UIImageJPEGRepresentation(pickedImage,0.75)

restaurante.imagem.insert(imageData, atIndex: imagemEscolhida-1)

I just need to save to the array the image compressed and i must use "Insert" so i can choose "imagemEscolhida-1" to put the image in the right position... It works with the PickedImage, but once its compressed it doesnt work.

thank you.

1

There are 1 best solutions below

0
On BEST ANSWER

imageData is an NSData object. You need to convert it back to UIImage.

Try this:

firstImageView.contentMode = .ScaleAspectFit

let imageData = UIImageJPEGRepresentation(pickedImage,0.75)!
let compressedImage = UIImage(data: imageData)!

restaurante.imagem.insert(compressedImage, atIndex: imagemEscolhida-1)