Re: Convenience Methods
Re: Convenience Methods
- Subject: Re: Convenience Methods
- From: "Adam R. Maxwell" <email@hidden>
- Date: Tue, 25 Sep 2007 19:33:06 -0700
On Sep 25, 2007, at 19:15, Nick Zitzmann wrote:
On Sep 25, 2007, at 8:10 PM, Jeff Laing wrote:
NSString's convenience methods are hiding class clusters, and I
stand by the
assertion that every one of them returns a valid NSString object.
They may
be subclasses of NSString but that does not make them non-NSString
objects.
Inheritance 101.
But class clusters are an implementation detail, and the code
shouldn't care. What's important is +[NSMutableString
stringWithString:] returns an NSMutableString, and +[NSString
stringWithString:] returns an NSString, despite the fact that
+stringWithString: is only defined by NSString.
Another good example is NSCharacterSet on 10.4 and earlier. The
following code causes a warning of "initialization from distinct
Objective-C type":
NSMutableCharacterSet *cset = [NSMutableCharacterSet
characterSetWithCharactersInString:@"test"];
because +[NSCharacterSet characterSetWithCharactersInString:] is typed
to return an NSCharacterSet instead of id. This is annoying (and
wrong), because it really is a mutable character set.
--
Adam
_______________________________________________
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