View Full Version : [Resolved] CGPoint conversion problem

May 26, 2011, 06:49 PM
I get “Lvalue required as left operand of assignment” error when compiling the following code. Can anyone help?
@interface myInfo: NSObject
CGPoint startPosition;
@property CGPoint startPosition;
@implementation myInfo
@synthesize startPosition;
myInfo* temp = [[myInfo alloc] init];
int ttt=100;
temp.startPosition.x = (CGFloat)ttt; << Compile error here

May 26, 2011, 07:27 PM
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:

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

// Assumes that you want the 'y' value to remain constant
temp.startPosition = CGPointMake(100,temp.startPosition.y);