Subclassing NSArray & NSMutableArray
So... i hear you can't subclass NSMutableArray and NSArray? For reasons only god and apple developers can tell us...

Well, while this might be true, you can still enjoy the functionality that you might expect from subclassing NSMutableArray. To do this, you subclass it and overwrite all the necessary methods and provide it with a backing store: NSMutableArray

Here is how it works:

CSSMutableArray.h:

    #import <Foundation/Foundation.h>
    
    
    @interface CSSMutableArray : NSMutableArray {
    	NSMutableArray *_backingStore;
    }
    
    @end

CSSMutableArray.m:

    #import "CSSMutableArray.h"
    
    
    @implementation CSSMutableArray
    
    - (id) init
    {
    	self = [super init];
    	if (self != nil) {
    		_backingStore = [NSMutableArray new];
    	}
    	return self;
    }
    
    - (void) dealloc
    {
    	[_backingStore release];
    	_backingStore = nil;
    	[super dealloc];
    }
    
    #pragma mark NSArray
    
    -(NSUInteger)count
    {
    	return [_backingStore count];
    }
    
    -(id)objectAtIndex:(NSUInteger)index
    {	
    	return [_backingStore objectAtIndex:index];
    }
    
    #pragma mark NSMutableArray
    
    -(void)insertObject:(id)anObject atIndex:(NSUInteger)index
    {
    	[_backingStore insertObject:anObject atIndex:index];
    }
    
    -(void)removeObjectAtIndex:(NSUInteger)index
    {
    	[_backingStore removeObjectAtIndex:index];
    }
    
    -(void)addObject:(id)anObject
    {
    	[_backingStore addObject:anObject];
    }
    
    -(void)removeLastObject
    {
    	[_backingStore removeLastObject];
    }
    
    -(void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject
    {	
    	[_backingStore replaceObjectAtIndex:index withObject:anObject];
    }
    
    @end

If you want to subclass NSArray, you only provide the Section titled NSArray.
You can now subclass from your "implementation of a custom NSArray subclass" and work as you wish.

Hope this helped... Peace!

Tomen =)
Subclassing NSArray & NSMutableArray
===

So... i hear you can't subclass NSMutableArray and NSArray? For reasons only god and apple developers can tell us...

Well, while this might be true, you can still enjoy the functionality that you might expect from subclassing NSMutableArray. To do this, you subclass it and overwrite all the necessary methods and provide it with a backing store: NSMutableArray

Here is how it works:

CSSMutableArray.h:

    #import <Foundation/Foundation.h>
    
    
    @interface CSSMutableArray : NSMutableArray {
    	NSMutableArray *_backingStore;
    }
    
    @end

CSSMutableArray.m:

    #import "CSSMutableArray.h"
    
    
    @implementation CSSMutableArray
    
    - (id) init
    {
    	self = [super init];
    	if (self != nil) {
    		_backingStore = [NSMutableArray new];
    	}
    	return self;
    }
    
    - (void) dealloc
    {
    	[_backingStore release];
    	_backingStore = nil;
    	[super dealloc];
    }
    
    #pragma mark NSArray
    
    -(NSUInteger)count
    {
    	return [_backingStore count];
    }
    
    -(id)objectAtIndex:(NSUInteger)index
    {	
    	return [_backingStore objectAtIndex:index];
    }
    
    #pragma mark NSMutableArray
    
    -(void)insertObject:(id)anObject atIndex:(NSUInteger)index
    {
    	[_backingStore insertObject:anObject atIndex:index];
    }
    
    -(void)removeObjectAtIndex:(NSUInteger)index
    {
    	[_backingStore removeObjectAtIndex:index];
    }
    
    -(void)addObject:(id)anObject
    {
    	[_backingStore addObject:anObject];
    }
    
    -(void)removeLastObject
    {
    	[_backingStore removeLastObject];
    }
    
    -(void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject
    {	
    	[_backingStore replaceObjectAtIndex:index withObject:anObject];
    }
    
    @end

If you want to subclass NSArray, you only provide the Section titled NSArray.
You can now subclass from your "implementation of a custom NSArray subclass" and work as you wish.

Hope this helped... Peace!

Tomen =)