Beginners confusion about objective c, assignment, properties etc
===

Sorry I couldn't be more descriptive in the title. I know C++ and C#, and a bit of Java, and I am doing some Objective C tutorials and can't explain what is going on here.

I will show you an example:

Here is the header/interface of the rectangle class:

    #import <Foundation/Foundation.h>
    
    @class XYPoint;
    @interface Rectangle : NSObject
    
    @property int width, height;
    
    -(int) area;
    -(int) perimeter;
    -(void) setW:(int)w andH:(int)h;
    -(XYPoint *) origin;
    -(void) setOrigin:(XYPoint*)pt;
    
    @end

Here is the implementation:

    #import "Rectangle.h"
    
    @implementation Rectangle{
        XYPoint *origin;
    }
    
    @synthesize width, height;
    
    -(void) setW:(int)w andH:(int)h
    {
        width = w;
        height = h;
    }
    
    -(int) area{
        return width*height;
    }
    
    -(int) perimeter{
        return (width+height)*2;
    }
    
    -(XYPoint *) origin{
        return origin;
    }
    -(void) setOrigin:(XYPoint*)pt{
        origin = pt;
    }
    
    @end

And here is my main program:

    #import <Foundation/Foundation.h>
    #import "Rectangle.h"
    #import "XYPoint.h"
    
    
    int main(int argc, const char * argv[])
    {
        @autoreleasepool {
          
            Rectangle *r = [[Rectangle alloc]init];
            XYPoint *p = [[XYPoint alloc]init];
            
            [p setX:100 andY:300];
            [r setW:6 andH:8];
            
            r.origin = p;
            
            NSLog(@"Width and height is %i %i", r.width, r.height);
            NSLog(@"Origin is at %i,%i", r.origin.x, r.origin.y);
            NSLog(@"Arear and perimeter are %i and %i", [r area], [r perimeter]);
            
        }
        return 0;
    }

The line `r.origin = p;` confuses me. Exactly which origin is being referred to here? The getter method as defined in the interface, or the actual member variable which is declared in the implementation?

Note origin is not a property.

To be honest I expected an error. The main program should only see the getter method, but it doesn't seem like a getter method that returns something could be on the left hand side of an assignment operator. Or is the system somehow mapping that syntax to a call to setOrigin?

I had expected the only possible way to set the origin would be something like `[r setOrigin: p]`

I can see how something like `r.width = 5` would work, as width as declared in the header as being a property, but I cannot see how `r.origin = p` works.

Can someone explain what is going on here?

Thanks.