Re: exception in class derived from NSMutableDictionary
Re: exception in class derived from NSMutableDictionary
- Subject: Re: exception in class derived from NSMutableDictionary
- From: Prachi Gauriar <email@hidden>
- Date: Wed, 30 Jul 2003 11:55:47 -0500
On Wednesday, July 30, 2003, at 11:03 AM, Robert G Palmer Jr wrote:
I have a class that I have derived from NSMutableDictionary - solely
for the purpose of being able to add items using a custom method. If
I execute either of the first two pieces of code, they work fine. If
I execute the third, I get an exception on the count method with the
following message:
2003-07-30 11:47:27.964 V360Locator[1766] An uncaught exception was
raised
2003-07-30 11:47:27.965 V360Locator[1766] *** -count only defined for
abstract class. Define -[VideoSensorCollection count]!
2003-07-30 11:47:27.965 V360Locator[1766] *** Uncaught exception:
<NSInvalidArgumentException> *** -count only defined for abstract
class. Define -[VideoSensorCollection count]!
Any help in expanding my understanding of this would be greatly
appreciated. Also, now that I look at it, would it not make sense to
have my "VideoSensorCollection" simply be a Category on the
NSMutableDictionary class?
<snip>
This has to do with NSDictionary and NSMutableDictionary being part of
a class cluster
<
http://developer.apple.com/documentation/Cocoa/Conceptual/Foundation/
Concepts/ClassClusters.html>.
The important thing is that to subclass, you have to override all of
NSMutableDictionary's primitive methods, namely -setObject:forKey: and
-removeObjectForKey:, as well NSDictionary's primitive methods, -count,
-objectForKey:, and -keyEnumerator. This is why you;re getting the
error with count.
I don't think providing a category would work in this case, because
you're dealing with a class cluster.
Are you sure this isn't a has-a relationship instead of an is-a
relationship? That is, could your class VideoSensorCollection just
have an NSMutableDictionary instance variable that you then cover with
some add and remove methods instead of subclassing?
-Prachi
_______________________________________________
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.