• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convenience Methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenience Methods


  • Subject: Re: Convenience Methods
  • From: glenn andreas <email@hidden>
  • Date: Tue, 25 Sep 2007 21:41:56 -0500


On Sep 25, 2007, at 9:33 PM, Adam R. Maxwell wrote:


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.

OTOH (unless this was changed from when I ran head first into it), doing:


NSMutableParagraphStyle *style = [NSMutableParagraphStyle defaultParagraphStyle];

also give you a warning which, in fact, is correct (since this returns an immutable NSParagraphStyle, not a mutable one that you might expect).

Proof that not everything in Cocoa is perfectly consistent everywhere (though I find the inconsistent usage of [-NSDocument fileName] vs [- NSSavePanel filename] more annoying).



Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures, fractals, art



_______________________________________________

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


References: 
 >RE: Convenience Methods (From: Jeff Laing <email@hidden>)
 >Re: Convenience Methods (From: Nick Zitzmann <email@hidden>)
 >Re: Convenience Methods (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: Convenience Methods
  • Next by Date: Re: Convenience Methods
  • Previous by thread: Re: Convenience Methods
  • Next by thread: Re: Convenience Methods
  • Index(es):
    • Date
    • Thread