• 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: A Question on estimating +arrayWithCapacity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Question on estimating +arrayWithCapacity


  • Subject: Re: A Question on estimating +arrayWithCapacity
  • From: Jonathan Hess <email@hidden>
  • Date: Fri, 9 Jan 2009 17:52:28 -0800

+[NSMutableArray array] returns a mutable array. That's the reason the return type is + (id) and not + (NSArray *).

When implementing connivence initializers, you should invoke [self alloc], not [ASpecificClass alloc]. Cocoa uses this pattern frequently, and you can safely depend on it.

Objective-c classes are first class objects. That's a difference from many other languages. Once you get uses to classes being first class objects, and the fact that classes can have dynamic messages, this becomes a lot more natural.

Good Luck -
Jon Hess

On Jan 9, 2009, at 5:45 PM, Kyle Sluder wrote:

On Fri, Jan 9, 2009 at 8:40 PM, Graham Cox <email@hidden> wrote:
Isn't guaranteed by the semantics of inheritance? I've specified the class:
[NSMutableArray ... and what I want it to give me... array]; And the fact
that NSMutableArray inherits NSArray ensures that anything that array can
do, NSMutableArray can do.

No, it means that NSMutableArray responds to everything NSArray responds to; there's no semantic guarantee. What if the subclass needs a different designated initializer, maybe one with more arguments? It would make sense for it to override the superclass's designated initializer to throw an exception. But without overriding the convenience constructor, this will blow up.

--Kyle Sluder
_______________________________________________

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

_______________________________________________

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: 
 >A Question on estimating +arrayWithCapacity (From: Steve Cronin <email@hidden>)
 >Re: A Question on estimating +arrayWithCapacity (From: Graham Cox <email@hidden>)
 >Re: A Question on estimating +arrayWithCapacity (From: Ken Thomases <email@hidden>)
 >Re: A Question on estimating +arrayWithCapacity (From: "Kyle Sluder" <email@hidden>)
 >Re: A Question on estimating +arrayWithCapacity (From: Graham Cox <email@hidden>)
 >Re: A Question on estimating +arrayWithCapacity (From: "Kyle Sluder" <email@hidden>)

  • Prev by Date: Re: A Question on estimating +arrayWithCapacity
  • Next by Date: Re: Bonjour server with multiple clients
  • Previous by thread: Re: A Question on estimating +arrayWithCapacity
  • Next by thread: Re: A Question on estimating +arrayWithCapacity
  • Index(es):
    • Date
    • Thread