Re: style question: when to use 'id' as return value?
Re: style question: when to use 'id' as return value?
- Subject: Re: style question: when to use 'id' as return value?
- From: Chris Suter <email@hidden>
- Date: Tue, 18 Dec 2007 09:33:47 +1100
On 18/12/2007, at 9:25 AM, Bill Bumgarner wrote:
On Dec 17, 2007, at 2:14 PM, Sean McBride wrote:
NSString has the method:
+ (id)stringWithString:(NSString *)aString
Why is the return value not an 'NSString*' instead of an 'id'? Is
this
just a stylistic preference, or...?
Because both NSString and NSMutableString Do The Right Thing when
that method is invoked and, thus, declaring that the method returns
a particular type of string -- mutable or immutable -- would be
wrong half the time.
NSString is a superclass of NSMutableString so it wouldn't be wrong to
say it returns NSString.
The real reason it returns id is for convenience: so that you don't
have to cast to get rid of the compiler warning.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden