Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Cannot assign to the result of the expression

I am upgrading my Objective-C code to Swift. I want to update the frame based on the image size like below:

let imageViewFrame: CGRect = view.frame
if (image.size.width <= image.size.height) {
     imageViewFrame.origin.x = (view.frame.size.width - view.frame.size.height)/4
     imageViewFrame.size.width = view.frame.size.height
}

here I am getting an error saying: "Cannot assign to the result of the expression" what I should do to remove the error?

Thanks in Advance!

like image 372
Keshav Avatar asked Jul 08 '14 10:07

Keshav


1 Answers

You're declaring imageViewFrame using let which makes it immutable.

You could use var instead of let for imageViewFrame which would make it mutable.

var imageViewFrame: CGRect = view.frame
like image 185
Anil Varghese Avatar answered Sep 20 '22 17:09

Anil Varghese