Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chen8002004

macrumors newbie
Original poster
May 22, 2011
26
0
I get “Lvalue required as left operand of assignment” error when compiling the following code. Can anyone help?
Declaration:
Code:
@interface myInfo: NSObject
{
    CGPoint startPosition;
}
@property     CGPoint startPosition;
@end
Definition:
Code:
@implementation myInfo
@synthesize startPosition;
@end
Use:
Code:
myInfo* temp = [[myInfo alloc] init];
int ttt=100;
temp.startPosition.x = (CGFloat)ttt; << Compile error here
 
Last edited:
The simple explanation is that the synthesized methods for structs (CGPoint, CGRect, etc) return a *copy* of the structure, not reference to it. Doing something like you are would simply set the value of 'x' on the returned copy and then discard the whole thing. You would need to do something like one of the below snippets:

Code:
CGPoint point = temp.startPosition;
point.x = 100;
temp.startPosition = point;

Code:
// Assumes that you want the 'y' value to remain constant
temp.startPosition = CGPointMake(100,temp.startPosition.y);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.