Note that there are some explanatory texts on larger screens.

plurals
  1. POInheritance Issues in Objective C
    primarykey
    data
    text
    <p>I created an "SDMutableGrid" class so that I could use a grid. It's just a child of NSMutableArray that contains a number for arrays equal to the number of rows in the grid.</p> <p>Currently, the program quits before it really starts and it appears that it is because the methods defined for NSMutableArray somehow do not apply to SDMutableGrid, anyone know why?</p> <p>Here is the .h :</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "SDDimensions.h" @interface SDMutableGrid : NSMutableArray { SDDimensions dimensions; } @property (nonatomic) SDDimensions dimensions; - (id)initWithDimensions:(SDDimensions)newDimensions; - (void)addObject:(id)anObject toRow:(NSUInteger)row; @end </code></pre> <p>Here is the .m :</p> <pre><code>#import "SDMutableGrid.h" @implementation SDMutableGrid @synthesize dimensions; - (void)setDimensions:(SDDimensions)newDimensions { if (newDimensions.width &lt; dimensions.width) { NSMutableArray *anArray; NSRange aRange = NSMakeRange(newDimensions.width, dimensions.width - newDimensions.width); for (NSUInteger i = 0; i &lt; MIN(dimensions.height,newDimensions.height); i++) { anArray = [self objectAtIndex:i]; [anArray removeObjectsInRange:aRange]; } } dimensions.width = newDimensions.width; if (newDimensions.height &gt; dimensions.height) { for (NSUInteger i = dimensions.height; i &lt; newDimensions.height; i++) { [self addObject:[[NSMutableArray alloc] initWithCapacity:dimensions.width]]; } } else if (newDimensions.height &lt; dimensions.height) { [self removeObjectsInRange:NSMakeRange(newDimensions.height, dimensions.height - newDimensions.height)]; } dimensions.height = newDimensions.height; } - (id)initWithDimensions:(SDDimensions)newDimensions { if (self = [super initWithCapacity:newDimensions.height]) { NSMutableArray *anArray; for (NSUInteger i = 0; i &lt; newDimensions.height; i++) { anArray = [[NSMutableArray alloc] initWithCapacity:newDimensions.width]; NSLog(@"Got this far"); [self addObject:anArray]; NSLog(@"woot"); [anArray release]; } NSLog(@"Finished Initializing grid"); } return self; } - (void)addObject:(id)anObject toRow:(NSUInteger)row { [[self objectAtIndex:row] addObject:anObject]; } @end </code></pre> <p>And here is what is appearing on the console:</p> <p><strong>2009-08-12 15:27:02.076 Flipswitch[1756:20b] <em></strong> Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '<strong></em> -[NSMutableArray initWithCapacity:]: method only defined for abstract class. Define -[SDMutableGrid initWithCapacity:]!' 2009-08-12 15:27:02.080 Flipswitch[1756:20b] Stack: ( 807902715, 2536648251, 808283725, 808264737, 13690, 11018, 10185, 814713539, 814750709, 814739251, 814722434, 814748641, 839148405, 807687520, 807683624, 814715661, 814752238, 10052, 9906 )</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload