Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C - Read-only variable is not assignable?

I've been using the following code to move views around, and never had a problem. I started using ARC in my project for the first time and I am getting the following error on the second line. "Read-only variable is not assignable"

Am I suppose to do this differently with ARC?

CGRect rect = self.frame;

[UIView animateWithDuration:0.4 animations:^{
    rect.origin.x = 57;
    self.frame = rect;
}];
like image 571
aryaxt Avatar asked Apr 06 '12 02:04

aryaxt


1 Answers

The problem was that I was using the CGRect inside an animation block. Marking the variable with __block solved my problem

__block CGRect rect = self.frame;
like image 170
aryaxt Avatar answered Oct 28 '22 16:10

aryaxt