Re: [NSMutableArray array]
Re: [NSMutableArray array]
- Subject: Re: [NSMutableArray array]
- From: "Patrick M. Rutkowski" <email@hidden>
- Date: Thu, 8 Apr 2010 10:35:14 -0400
Ah, hmm; well in the case of them both being NSCFArray's, that does
sound right; thanks :-)
What I was worried about is that maybe NSMutableArray (or any
sub-class in general) would need to do some special sub-class-specific
initialization, which it might not have implemented. I guess though,
if you're going to be sub-classing a class, then you ought to
generally make sure that all of it's static method will work on your
new sub-class?
There's always the danger that the super-class will have new static
methods added without your knowledge though.
-Patrick
On Thu, Apr 8, 2010 at 10:25 AM, Dave DeLong <email@hidden> wrote:
> Yes, that is safe to use. It's safe to use because classes are really just special objects, which means they get all the class method inheritance that instances get with instance methods. This will work in every case where the implementors have used:
>
> [[[self alloc] init] autorelease] //this will instantiate a new instance of whatever class invokes this method
>
> Instead of
>
> [[[MyClass alloc] init] autorelease] //this will instantiate a new instance of MyClass, regardless of which class invoked this method
>
> Just like in instance methods, class methods have an implicit "self" variable that refers to the Class itself.
>
> Beyond that, NSMutableArray and NSArray are really just the same class (NSCFArray, usually), with mutability determined by an internal flag.
>
> Cheers,
>
> Dave
>
> On Apr 8, 2010, at 8:20 AM, Patrick M. Rutkowski wrote:
>
>> Is is safe to do [NSMutableArray array], even with the "array" class
>> method is actually declared as +[NSArray array]. In other words, is it
>> safe to call a super-class' class method.
>>
>> If not, why?
>>
>> If so, why? And also, is it generally safe in _all_ cases, or only
>> just when specifically crafted to work?
>>
>> Many thanks,
>> -Patrick
>
> _______________________________________________
>
> 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