Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.objective-c > #253
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
| Newsgroups | comp.lang.objective-c |
| Subject | Re: Is my analysis of this simple issue correct? |
| Date | Wed, 03 Feb 2016 21:01:54 +0100 |
| Organization | Informatimago |
| Lines | 48 |
| Message-ID | <87wpqlh8b1.fsf@kuiper.lan.informatimago.com> (permalink) |
| References | <n8rplo$c3t$1@news.albasani.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net pW84DkxAgSBMvykV27NSHwG9BBdFOMomgcQQv4yScWNAWtVEq0 |
| Cancel-Lock | sha1:MDM0Yjc4NWRlNTY3ZTQ4NTVkMjY4ZjEwMTgyZTNiZjc3OTU5MmQ2Ng== sha1:jXjOweuctJRrmbLgiLlnBDTmMMA= |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== |
| X-Accept-Language | fr, es, en |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
| Xref | csiph.com comp.lang.objective-c:253 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar
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