Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 15, 2017, 01:23:12 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Ex 9.4 - convert add: to take and return 'id' types.  (Read 6524 times)
simoncurry24
Newbie
*
Posts: 1


Email
« on: February 08, 2012, 10:25:50 AM »

Hi,

I could not get the code to work with id objects. I would get the error message "Property 'numerator' not found on object of type "__strong id"

I managed to get it to work by reverting to message sending format.

Can you confirm that property dot notation is not available with 'id' types?

Thanks!
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: February 08, 2012, 10:37:05 AM »

Yes, that's correct.  You can't use the dot operator with id objects.   Not sure if I mentioned that in the text somewhere or not.


Cheers,

Steve
Logged
Hesadanza
Newbie
*
Posts: 28


« Reply #2 on: February 09, 2012, 08:19:44 PM »

I ran into the same issue, and was confused.  I didn't know I couldn't use dot notation with id objects, so I didn't know what was going on.  Did I miss that in the text?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #3 on: February 10, 2012, 11:16:42 AM »

I meant to mention it in the text with the 4th edition, but it looks like it slipped through the crack!  Sad

Steve
Logged
Hesadanza
Newbie
*
Posts: 28


« Reply #4 on: February 10, 2012, 11:21:27 AM »

I read elsewhere that some programmers consider dot notation bad form, even with properties, because it obscures the "message sending/receiving" format of object oriented programming.  Is that true?  Would it be better to keep with one form or the other, or do many programmers mix them?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #5 on: February 10, 2012, 11:27:37 AM »

It's become a topic of debate.  It's a subjective decision.  I like using the dot operator for properties.   Writing an expression like myRect.origin.x is a lot easier to write and read than [[myRect origin] x], in my opinion.  Further, you use the same name to refer to the property whether you're setting or retrieving its value (e.g., myOrigin.x = 5 instead of [myOrigin setX: 5]).

Cheers,

Steve
« Last Edit: February 10, 2012, 11:30:02 AM by skochan » Logged
BombermanX
Newbie
*
Posts: 4


Email
« Reply #6 on: February 17, 2012, 04:57:46 PM »

Is it really necessary to set arguments and return types from object* to id for polymorphism? In your example of complex and fraction add methods, both accept and return objects so don't actually cause errors when using id objects on them - as long as you assign the correct object - and the dot.notation still works in those methods, too.
 
Logged
jonathan
Newbie
*
Posts: 5


Email
« Reply #7 on: August 14, 2012, 08:49:18 AM »

it is  mention in the 4th edition as a note... but i forgot i m going to try that without the dot....Smiley tknx
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.