• 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: "Clark Cox" <email@hidden>
  • Date: Wed, 11 Jun 2008 08:45:32 -0700

On Wed, Jun 11, 2008 at 12:01 AM, John Engelhart
<email@hidden> wrote:
>
> On Jun 10, 2008, at 11:28 AM, Charles Srstka wrote:
>>
>> I think the problem is that if NSArray has +[NSArray array] returning an
>> NSArray, then NSMutableArray has to return an NSArray also, since it can't
>> have a different method signature for the same method. As a result, if you
>> called +[NSMutableArray array], the compiler would think you were getting a
>> regular, non-mutable NSArray, and you'd get a warning if you tried to do
>> this, although the code would still work:
>
> No, each class is allowed to define different types for the same method:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_9_section_2.html#//apple_ref/doc/uid/TP30001163-CH16-TPXREF161
>
> This whole business about '(NSArray *) means NSArray AND any of it's
> subclasses' is the result of sloppy thinking and confusing 'able to' with
> 'as per spec'.
>
> If you declare a method prototype as '-(NSArray *)resultsArray', then you
> have explicitly communicated that a NSArray is going to be returned.  Not a
> NSMutableArray. Not 'Jimmies groovy array with red pin stripes'.

This is simply not true. Returning (NSArray*) only means "I will
return an object that you can assume is an NSArray". Not a single one
of the convenience methods on NSArray actually return an NSArray, they
all return one subclass or another.

>A NSArray. Period.  A NSMutableArray != a NSArray.

No, All NSMutableArrays are also NSArrays, that is the very definition
of subclassing. In any object-oriented system, subclassing establishes
an "is-a" relationship between classes.


> If you're going to be returning (or accepting) more than a single class, you use id, which clearly communicates your intentions.

Again, no. It is perfectly acceptable to pass an NSMutableArray where
an NSArray is expected.

--
Clark S. Cox III
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

  • Follow-Ups:
    • [moderator] Re: Garbage collector vs variable lifetime
      • From: Scott Anguish <email@hidden>
References: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <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>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Charles Srstka <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)

  • Prev by Date: Re: Link to zlib
  • Next by Date: Re: Link to zlib
  • Previous by thread: Re: Garbage collector vs variable lifetime
  • Next by thread: [moderator] Re: Garbage collector vs variable lifetime
  • Index(es):
    • Date
    • Thread