Amazon.com Widgets Page.200, Chapter 9
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 16, 2014, 02:22:21 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
|-+ Old Stuff
| |-+ Errata
| | |-+ Current Errata
| | | |-+ Page.200, Chapter 9
Pages: [1] Go Down
Print
Author Topic: Page.200, Chapter 9 (Read 9595 times)
Inuki
Newbie
*
Posts: 3






on: May 18, 2011, 11:40:38 AM

With respect to the text:

"The test
     if ( [Square respondsTo: @selector (alloc)] == YES )
tests whether the class Square responds to the class method alloc, which it does because its inherited from the root object NSObject."

The statement above turns out to be a syntax error in my XCode4 and I found there's no such a method as:
    +(BOOL) respondsTo : (SEL) aSelector
defined in <NSObject.h> or elsewhere as well. Or did I miss anything before?
Last Edit: May 18, 2011, 11:46:39 AM by Inuki Logged
mitchb
Full Member
***
Posts: 139






Reply #1 on: May 21, 2011, 03:37:01 PM

The method should be  "respondsToSelector:"

if ( [Square respondsToSelector: @selector (alloc)] == YES )

See the program example on page 199 for usage.

Mitch
Logged

If you give a man a program, you will frustrate him for a day;
If you teach him how to program, you will frustrate him for a lifetime;
     - Anonymous
Inuki
Newbie
*
Posts: 3






Reply #2 on: May 30, 2011, 04:07:59 AM

The method should be  "respondsToSelector:"

if ( [Square respondsToSelector: @selector (alloc)] == YES )

See the program example on page 199 for usage.

Mitch



Thanks mate, I think I found something interesting here.
Actually respondsToSelector: is NOT a class method and should not have been invoked directly on the class itself, namely, Square here. However, your code above can be compiled and run successfully in the OC environment, which is not the case in other languages such as Java. And when used in the "static" way, respondsToSelector: can only recognize and identify those same "static" class methods, while returns NO to the instance methods. Since method overloading is not allowed in OC, I wonder if it's true that other instance methods also have such "unrevealed" effects when used in such a "static" style.

Regards,
alex
Logged
Inuki
Newbie
*
Posts: 3






Reply #3 on: May 30, 2011, 04:24:24 AM

And as you reminded me, both the static way and non-static way were applied on P.199, I think it deserves more explanation here.

....
if ( [mySquare respondsToSelector: @selector (setWidth:andHeight:)] == YES )   //normal way
....
if ( [Square respondsToSelector: @selector (alloc)] == YES )   //static way
....

And here is the signature of respondsToSelector: in <NSObject.h>

         - (BOOL)respondsToSelector:(SEL)aSelector;
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.