Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:43:03+00:00 2026-06-08T18:43:03+00:00

Sorry I couldn’t be more descriptive in the title. I know C++ and C#,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:43:05+00:00Added an answer on June 8, 2026 at 6:43 pm

    Your guess is right – that syntax, called dot notation, is translated into a call to [r setOrigin:p] by the compiler. The general idea is that just like most other languages, you have getters and setters for object properties; in Objective-C, these are usually written as:

    - (type)variableName;
    - (void)setVariableName:(type)aVariable;
    

    So long as your own code conforms to these conventions, you can use dot notation to both get and set variables on your classes, and trust that your methods are called.

    There’s obviously a lot more going on behind the scenes, so I hope this brief explanation is enough for you for now. If you’re interested, though, you can look further into:

    • Synthesizing properties and what actually happens – methods of the form shown above are generated by the compiler, along with instance variables for actual data storage
    • Key-value coding, which takes advantage of these principles and conventions
    • Special cases for some types (for example, BOOL variables’ getters are usually written as -isVariableName rather than -variableName), and how you can manage them with @property attributes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry I couldn't think of a more descriptive title: We have an issue with
I know the title is vague, sorry I couldn't think of a better way
Sorry, couldn't find a more appropriate title. In My code I have two classes
Sorry the title is a bit crappy, I couldn't quite word it properly. Edit:
Sorry about the title, I couldn't think of a better way to describe the
Sorry for the title, I couldn't argue something better. Here is my question: Is
Sorry, poorly descripted title and couldn't think of how to phrase it. Working on
Sorry for dodgy title, couldn't think of anything better... Anyway, I have written a
Sorry for the awful title, I couldn't think of anything better. Basically I have
Sorry couldn't think of a better title. :) Here goes, I have been pulling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.