IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Its a floor polish and a dessert topping
First, when you say something like

id <PFoo> something = otherThing;

you are saying that whatever something references is guaranteed to conform to that protocol (PFoo) - but nothing else can be assumed. If you intend to send messages not in the protocol to that reference - expect a warning (but the code will work fine). These kinds of "typed" references are not used that much in practice but they are useful for signalling intent and can catch errors. Another thing you might realize is that otherThing can be a reference to an object that implements PFoo's protocol (garble) without actually having PFoo in the protocol list. ie, anything that implement's garble is OK. There's also a nice check conformsToProtocol: you can use to make sure what you've been handed is what you expect.

OK, back to the warning:

If you take a look at NSObject.h, you'll find that NSObject is both a protocol, and a class.

IOW,

@protocol NSObject
...
- (id)retain;
- (oneway void)release;
- (id)autorelease;
- (unsigned)retainCount;
...

@end

and then you'll find that NSObject the class is defined as

@interface NSObject <NSObject>
...
- (id)retain;
- (oneway void)release;
- (id)autorelease;
- (unsigned)retainCount;
...
@end

So, if you want to, you could define your interface as extending NSObject:

@interface PFoo <NSObject>
...
@end

Which will get you all the retain stuff included in your protocol. There's no problem with declaring a protocol multiple times in the inheritance chain.

Or just define the reference as a Yodel* or plain old id.




"I made up the term 'object-oriented', and I can tell you I didn't have C++ in mind"
    - Alan Kay, OOPSLA '97
New Re: Its a floor polish and a dessert topping
So, if you want to, you could define your interface as extending NSObject:
Great. That's the bit I was missing. Thanks.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
     ObjC question - (admin) - (2)
         Its a floor polish and a dessert topping - (tuberculosis) - (1)
             Re: Its a floor polish and a dessert topping - (admin)

Shpongle.
52 ms