Re: [NSMutableArray array]
Re: [NSMutableArray array]
- Subject: Re: [NSMutableArray array]
- From: glenn andreas <email@hidden>
- Date: Thu, 08 Apr 2010 14:03:26 -0500
On Apr 8, 2010, at 12:29 PM, Bill Bumgarner wrote:
>
> On Apr 8, 2010, at 10:21 AM, Patrick M. Rutkowski wrote:
>
>> Agreed, but there's always the danger the +array method, which might
>> actually be implemented in NSArray.m, will not properly initialize the
>> more specific NSMutableArray object.
>>
>> Of course, in this specific case that's the case, but it might be the
>> case with other class hierarchies.
>>
>> But, nonetheless I'm troubled that nobody in this thread has
>> acknowledged that yet :-o
>
> Because, in practice, that doesn't generally happen.
>
> Across the system supplied frameworks, classes generally have designated initializers and those initializers are inherited properly. The convenience creation methods -- factory methods, if you will -- are dead simple stupid, generally doing the equivalent of '[[[self alloc] init*] autorelease]' where the init part calls the designated initializer.
There is a problem with "things that look like convenience creation methods but aren't" - most notably +[NSParagraphStyle defaultParagraphStyle]. You might expect:
NSMutableParagraphStyle *ps = [NSMutableParagraphStyle defaultParagraphStyle];
[ps setAlignment: NSCenterTextAlignement];
to work. It doesn't (since ps is actually an immutable NSParagraphStyle).
The major clue that is isn't a convenience creation method being found in the declaration:
- (NSParagraphStyle *) defaultParagraphStyle;
instead of:
- (id) defaultParagraphStyle;
Glenn Andreas email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL
_______________________________________________
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