Re: NSObject vs id

Gordon Henriksen <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Sep 3, 2009, at 12:05, Florent Lacheroy wrote:

> I would like to collect your thoughts about a subject:
>
> I wonder wether it is better to use NSObject or id.

In practice, you can quite safely assume that all classes derive from  
NSObject. Given that, the dominant consideration is that 'id' involves  
less typing than 'NSObject*'.

> I have seen Apple is making intensive use of id in its API.
> But sometimes it looks very permissive like in NSMutableDictionary -  
> setObject:forKey: or
> This class need to retain its entries but the method does not  
> require the object in argument to responds to "retain".
> I assume that they want their objects to stay as flexible as  
> possible but they could require at least the NSObject protocol in  
> the example I gave

This is unlikely to be changed. But you could use NSObject* values in  
your own code if you prefer.

— Gordon
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.