1

I'm trying to create a CGRect property.

@property (nonatomic) CGRect myRect;

Then later on, I set the frame:

self.myRect = self.frame;
self.myRect.size.height = 10; // Error

I get an error saying "Expression is not assignable". Why do I get that? Can't I change the size of a CGRect?

Jessica
  • 9,379
  • 14
  • 65
  • 136

2 Answers2

1

Do it this way.

_myRect = self.frame;
_myRect.size.height = 10;
Rajesh Maurya
  • 3,026
  • 4
  • 19
  • 37
1

self.myRect.size.height = 10 is equivalent to [ self myRect ].size.height = 10

You must read the CGRect property, modify it, then write it back:

CGRect r = [ self myRect ] ;
// modify r here
[ self setMyRect:r ] ;

or:

CGRect r = self.myRect ;
// modify r here
self.myRect = r ;
nielsbot
  • 15,922
  • 4
  • 48
  • 73