1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Resolved CGPoint conversion problem

Discussion in 'iPhone/iPad Programming' started by chen8002004, May 26, 2011.

  1. chen8002004, May 26, 2011
    Last edited: May 27, 2011

    macrumors newbie

    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
  2. macrumors 6502a

    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);

Share This Page