• 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: Garbage collector vs variable lifetime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Garbage collector vs variable lifetime


  • Subject: Re: Garbage collector vs variable lifetime
  • From: Charles Srstka <email@hidden>
  • Date: Tue, 10 Jun 2008 10:19:58 -0500

On Jun 9, 2008, at 1:39 PM, Chris Hanson wrote:

It is perfectly legal to return an NSMutableArray from a hypothetical +(NSArray *)array method.

However, all the sender of that +(NSArray *)array message can know is that the result can be treated as an NSArray. It can't know whether an NSArray or NSMutableArray is returned (unless it does extra work, like using -isKindOfClass:, which also happens to be fragile).

Even isKindOfClass: won't work in this case, because NSArray and NSMutableArray both usually end up being the same class, NSCFArray. This class seems to be a subclass of NSMutableArray, and using isKindOfClass: on it will always return YES for NSMutableArray, even if it's not actually mutable.


I don't really know of any way to actually test whether an NSArray is mutable or not programatically (well, I suppose you could try mutating it and see if you catch an exception or not, but that's obviously not a very good solution).

Charles
_______________________________________________

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: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Bill Bumgarner <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)

  • Prev by Date: changing locale
  • Next by Date: Re: 3rd Party Nonsense (was Re: Regular Expressions?)
  • Previous by thread: [moderator] Re: Garbage collector vs variable lifetime
  • Next by thread: Re: Garbage collector vs variable lifetime
  • Index(es):
    • Date
    • Thread