Re: Problem overriding NSMutableArray?
Re: Problem overriding NSMutableArray?
- Subject: Re: Problem overriding NSMutableArray?
- From: Andreas Monitzer <email@hidden>
- Date: Thu, 31 May 2001 12:08:18 +0200
On Wednesday, May 30, 2001, at 11:43 , Michael Rogers wrote:
I have a class called PhotoAlbumArray that subclasses NSMutableArray (to
be used as a delegate of an NSTableView). PhotoAlbumArray has been
instantiated in the nib file of my project, and connected to the delegate
of an NSTableView.
Unfortunately, at runtime I get errors such as those shown below:
May 30 16:01:49 PhotoAlbum[880] An uncaught exception was raised
May 30 16:01:49 PhotoAlbum[880] *** -objectAtIndex: only defined for
abstract class. Define -[PhotoAlbumArray objectAtIndex:]!
May 30 16:01:49 PhotoAlbum[880] *** Uncaught exception:
<NSInvalidArgumentException> *** -objectAtIndex: only defined for
abstract class. Define -[PhotoAlbumArray objectAtIndex:]!
My first question is, what abstract class? NSMutableArray is concrete,
so presumably its subclass is too.
No:
file:///System/Library/Frameworks/Foundation.framework/Versions/C/Resources/
English.lproj/Documentation/Reference/ObjC_classic/Classes/NSArray.html
NSArray and NSMutableArray are part of a class cluster, so arrays are not
actual instances of the NSArray or NSMutableArray classes but of one of
their private subclasses. Although an array's class is private, its
interface is public, as declared by these abstract superclasses, NSArray
and NSMutableArray.
I've overridden -(id)initWithCapacity: and -(void)awakeFromNib:, and the
fact that the NSLog() statements in both aren't being executed suggests
something's wrong. Come to think of it, when *does* initWithCapacity get
called? How does, by putting it in the nib, the nib figure out that that'
s the particular init routine that I want done? I guess it doesn't, and
that I should be overriding just init.
I think you should use HAS_A rather than IS_A.
Comments and clarification of the above would be greatly appreciated!
On a related matter, what are the advantages of using a class method +(id)
arrayWithCapacity: as opposed to -(id)initWithCapacity:
The first one returns an autoreleased object.
andy
--
Description forthcoming.