• 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: Initialising NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initialising NSMutableArray


  • Subject: Re: Initialising NSMutableArray
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 13 Jul 2009 09:41:05 -0700

On Jul 13, 2009, at 08:49, I. Savant wrote:

Subclassing is fraught with many angry, fire-breathing, treasure- grubbing dragons and as such is *not* recommended.

On Jul 13, 2009, at 08:51, David W. Berry wrote:

NSMutableArray (and most/all of the collection classes) is an abstract class that can't be usefully sub-classed. The object returned by [NSMutableArray array] is actually a subclass of NSMutableArray.

As someone who's been guilty of making statements like these in the past, I just want to say : it ain't so. Subclassing NSArray is pretty easy (there are 5 primitive methods to override and you're done). What you *don't* get for free from subclassing is an internal storage mechanism -- you have to invent that for yourself (usually by putting a real NSArray instance variable in your subclass :) ). You also need a pretty clear understanding of how class clusters work, and that's where confusion can set in. The OP didn't have a clear understanding, and that led to his problem.


For the record, too, [NSMutableArray array] will normally return an object of the same concrete class as [NSArray array]. In Apple's implementation, they're the same thing, with the mutability enforced at run time. That's an implementation detail, of course, but it's worthwhile being aware of it.


_______________________________________________

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


  • Follow-Ups:
    • Re: Initialising NSMutableArray
      • From: "I. Savant" <email@hidden>
References: 
 >Initialising NSMutableArray (From: DKJ <email@hidden>)
 >Re: Initialising NSMutableArray (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: [iPhone] Network connection between 2 iPhones
  • Next by Date: Re: NSError in NSDocument readFromURL
  • Previous by thread: Re: Initialising NSMutableArray
  • Next by thread: Re: Initialising NSMutableArray
  • Index(es):
    • Date
    • Thread