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

  • Home
  • SEARCH
  • 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 1011277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:12:36+00:00 2026-05-16T09:12:36+00:00

I am new Objective C. I am trying to understand and workout problems from

  • 0

I am new Objective C. I am trying to understand and workout problems from Stephen Kochan’s Programming in objective c 2.0. This problem is from chapter 8.

What I don’t understand is: why can’t I assign variable values directly when I can get them.

For example:

This does not give me a error or warning. But it also does not set the value of X and Y.

go.origin.x = 300;
go.origin.y = 100;

But, this works fine and gives me the intended result:

NSLog (@"print %i, %i", go.origin.x, go.origin.y);

Here is my XYPoint.h

#import <Foundation/Foundation.h>

@interface XYPoint : NSObject {

    int _x;
    int _y;

}
@property int x;
@property int y;

@end

XYPoint.m

#import "XYPoint.h"

@implementation XYPoint

@synthesize x = _x;
@synthesize y = _y;
@end

GraphicObject.h

#import <Foundation/Foundation.h>
#import "XYPoint.h"

@interface GraphicObject : NSObject {

    XYPoint *_origin;
}

@property (nonatomic, retain) XYPoint *origin;

-(void) setOrigin : (XYPoint *) pt;

@end

GraphicObject.m

#import "GraphicObject.h"

@implementation GraphicObject

@synthesize origin = _origin;

-(void) setOrigin : (XYPoint *) pt {

    _origin = [[XYPoint alloc] init];

    _origin = pt;

    //_origin.x = pt.x;
    //_origin.y = pt.y;

}

@end

Also if don’t want my origin.x and origin.y to be changed when I change my xypoint x and y, why do I have to do this:

_origin.x = pt.x;
_origin.y = pt.y;

and why not just:

_origin = pt;

For example in the main file:

XYPoint *myPoint = [[XYPoint alloc] init];
go.origin = myPoint;

myPoint.x = 250;
myPoint.y = 50;

NSLog(@"Origin values %i, %i", go.origin.x, go.origin.y);

myPoint.x = 100;
myPoint.y = 10;

NSLog(@"Origin values %i, %i", go.origin.x, go.origin.y);

I understand that the values of origin don’t change. But do I have to, in the setOrigin: method, assign it in this way:

_origin.x = pt.x 

and not like this:

_origin = pt;

Thanks everyone. I know this is a long question. I really tried to understand and also looked in many places but I don’t even know what to search for. What do you call this kind of assignment?

  • 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-05-16T09:12:36+00:00Added an answer on May 16, 2026 at 9:12 am

    Congrats! You’ve discovered that Objective-C properties are syntactic sugar around a getter method and a setter method. Because a property is not truly a field of an object (as x and y are fields of a CGPoint structure), modifying fields of the object’s properties does nothing–the code is resolved to mean “get the value of the property, then modify the resultant copy of that value.”

    Now, you can chain property gets and sets (e.g. anObject.widget.gear.speed *= 2) and you can chain field gets and sets (e.g. myStructure.owner.uniqueID = rand()) and, as you can see, they look pretty much identical. But you can’t mix and match them.

    Why?

    Well, because… you can’t. And that’s pretty much it. So, in the future, if you’re having these sorts of problems, check to see if you’re mixing and matching properties and fields. If so, you’ll have to break it apart:

    CGPoint pt = go.origin;
    pt.x += 300;
    pt.y -= 100;
    go.origin = pt;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to objective c and am trying to understand how/when autorelease is
I am new in objective-c and I am trying to understand memory management to
I'm new to Objective-C and iPhone development, and I'm trying to store floating-point values
Still new to Objective C, and I'm having some trouble that I just can't
I'm new with Objective-C, so there probably is a simple solution to this. I
How do I implement this method (see below)? I'm new to Objective-C and I'm
I'm still pretty new to Objective -C and iPhone development and am trying to
I am a new Objective-C programmer coming from a C#, VB.NET, Etc. These are
I'm new to objective-c and Im trying to write a little sample app that
Completely new to Objective-C, trying to find out when I need to alloc and

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.