Re: Subclass of NSMutableArray isn't working
Re: Subclass of NSMutableArray isn't working
- Subject: Re: Subclass of NSMutableArray isn't working
- From: Shawn Erickson <email@hidden>
- Date: Wed, 10 Mar 2004 09:26:09 -0800
On Mar 10, 2004, at 8:44 AM, Jamie Griffin wrote:
If the Graph class that you are making is intended to be used by
other objects as an Array (in other words external objects are
calling the count, addObject:, objectAtIndex:, etc methods directly)
then maybe you really do want an NSMutableArray subclass.
I'm afraid that's exactly what I want. The outside world makes
considerable use of NSMutableArray methods on Graph objects. I
basically want a Graph to be an NSMutableArray with some additional
methods (but no additional data), which seems like the perfect case
for a subclass.
I have read up on class collections and have created my own data
representation (an NSMutableArray inside) and overridden the primitive
class and instance methods (I simply pass the buck for all, ex: -count
has the implementation: return [internalArray count]). Now the class
works as an NSMutableArray and responds to inherited methods but does
not respond to my own instance methods. Any ideas?
I am open to the alternative of creating an NSObject subclass with an
internal array. However, to do this I would need to find a way of
passing messages to the array if my class does not respond to them
(kind of like a subclass does naturally...). Would a delegate be
appropriate?
If you just want additional methods consider adding the methods you
want to a standard NSMutableArray by using a category. For example...
@implementation NSMutableDictionary (FTSWSerialPortAdditions)
- (void)setSerialPortSpeed:(int)speed
{
[self setObject:[NSNumber numberWithInt:speed]
forKey:FTSWSerialPortSpeed];
}
...
@end
@interface NSMutableDictionary (FTSWSerialPortAdditions)
- (void)setSerialPortSpeed:(int)speed;
...
@end;
-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.