Re: NSObject vs id

Bill Bumgarner <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Sep 3, 2009, at 10:14 AM, Christiaan Hofman wrote:

> The basic rule is that you can assume that all objects (type id)  
> should at least respond to the basic memory management methods and - 
> description (basically the Cocoa counterparts of CFBase.h).

For practical purposes only, you can assume that.

If I implement:

@interface Rootonomous
@end

Instances of said class will not implement any methods.  Though rare  
and typically limited purely to research purposes, there are reasons  
to implement such a class (actually, it is an interesting thought  
exercise to take the above and design your own object library w/your  
own patterns of use).

Such classes cannot be used in the context of the Foundation [unless  
you were to implement <NSObject>, which kind of defeats the purpose of  
the exercise), though, certainly and, thus, Christiaan's statement is  
true in the context of Cocoa programming, for all intents and purposes.

> For other methods you should first know they responds, usually using  
> respondsToSelector: (or you know it from a context, e.g. when the  
> object is a delegate or dataSource with required methods).

Using respondsToSelector: outside of delegation or protocols with  
optional methods is generally a sign that your design has gone in an  
unfortunate direction.

b.bum
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.