Amazon.com Widgets 9.4 no errors or warnings when using add: method with id as receiver
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 31, 2014, 12:21:51 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ Exercises
| | |-+ Chapter 9
| | | |-+ 9.4 no errors or warnings when using add: method with id as receiver
Pages: [1] Go Down
Print
Author Topic: 9.4 no errors or warnings when using add: method with id as receiver (Read 792 times)
afterDark
Global Moderator
Full Member
*****
Posts: 131






on: November 22, 2012, 10:50:10 AM

In question 9.4, I accidentally forgot to rename the add: methods. But the program compiles and runs without any warnings. Did I miss something? I would like to see what it looks like, if I ever use a method on a id receiver when that methodname is already taken.

As you can see in the code below, I tried a slightly different approach with Fraction instances and with Complex instances, to see if that made a difference. It doesn't, as all of this runs smoothly.

This is the relevant fragment from main.m (I reuse c1 en f1 from earlier in the program):
Code: (Objective-C)
id result, dataValue1, dataValue2;
       
//assign Fraction instances to the id type dataValue's
Fraction *f2 = [[Fraction alloc] init];
[f2 setTo:34 over:12];
       
dataValue1 = f1;
dataValue2 = f2;
result = [dataValue1 add:dataValue2];
[result print];

//assign Complex instances to the id type dataValue's
dataValue2 = [[Complex alloc] init];
[dataValue2 setReal:2 andImaginary:99.8];
       
dataValue1 = c1;
result = [dataValue1 add:dataValue2];
[result print];

Would anyone know why there is no complaint that the method add: is found in more than one class?

edit: only now I realise that maybe my XCode version has something to do with this. I use XCode 4.5.1 on OS X 10.7.5
Last Edit: November 22, 2012, 11:53:00 AM by afterDark Logged

I am just an amateur with Objective-C, don't let the moderator label fool you. Working my way through the book slowly.
bertobettencourt
Newbie
*
Posts: 45


Email




Reply #1 on: October 23, 2013, 09:44:51 PM

Maybe your Xcode version is higher than the one being used by the book and this was corrected.

Or your id type just knew exactly where to go. You still should change the method name to not receive unexpected errors, especially ones that will make you go crazy because you can't find anything wrong.

Cheers.
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

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 (c) 2009 classroomM.com. All rights reserved.