Groups | Search | Server Info | Login | Register


Groups > comp.lang.objective-c > #253

Re: Is my analysis of this simple issue correct?

From "Pascal J. Bourguignon" <pjb@informatimago.com>
Newsgroups comp.lang.objective-c
Subject Re: Is my analysis of this simple issue correct?
Date 2016-02-03 21:01 +0100
Organization Informatimago
Message-ID <87wpqlh8b1.fsf@kuiper.lan.informatimago.com> (permalink)
References <n8rplo$c3t$1@news.albasani.net>

Show all headers | View raw


Jon Rossen <jonr17@comcast.net> writes:

> As a relative beginner in all of this, I'd really appreciate it if
> someone could give me some feedback as to whether my analysis of the
> issue I ran into is correct.
>
> The explanation for this seems really simple, and I think I know what
> it is but I'm not 100% sure. I'm seeing for a simple expression, I get
> an error when I use bracket/message syntax but using dot.notation is
> fine.
>
> I have a simple method, and it's using the parent class's getter to
> tweak an ivar.  Here's the line in question:
>
> I can do this with no error:   self.x = self.x * m;
> of this with no error:         self.x = [self x] * m;
>
> But I can't do this:          [self x] = self.x * m;
> or this:                      [self x] = [self x] * m;
>
> The error I get here:   "Assigning to 'readonly' return result of an
> Objective-C message not allowed"
>
> The error makes sense and when thinking about I thought to myself
> DOH!!!! (a few times).
>
> The reason why dot notation works on the result is that the dot
> notation syntax can sort of 'morph' between setter and getter by use
> of the '=' to assign a value..voila you have the setter.  That's
> essentially what the examples with 'self.x = blah blah blah' is doing,
> and it's valid.
>
> For [self x], the message syntax is one of a getter and thus is
> readonly.  So, therefore in order to use message syntax you have to
> follow through with it properly and use the setter: Put the code on
> the right of the '=' as the argument to the setter method:  In other
> words:
> [self setX:self.x * m];
>
> Is my assessment of this pretty much correct?

Yes.

-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

Back to comp.lang.objective-c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Is my analysis of this simple issue correct? Jon Rossen <jonr17@comcast.net> - 2016-02-02 18:46 -0800
  Re: Is my analysis of this simple issue correct? "Pascal J. Bourguignon" <pjb@informatimago.com> - 2016-02-03 21:01 +0100
  Re: Is my analysis of this simple issue correct? spikeysnack <spikeysnack@gmail.com> - 2016-02-04 01:43 -0800

csiph-web