Re: Using invocation forwarding
Re: Using invocation forwarding
- Subject: Re: Using invocation forwarding
- From: Jonathan Wight <email@hidden>
- Date: Tue, 16 Dec 2003 11:42:38 -0600
It really isn't that tough. Create a subclass of NSDictionary. Make an
NSDictionary a member variable of your class. Provide impementations of
"- (unsigned)count", "- (NSEnumerator *)keyEnumerator" and "-
(id)objectForKey:(id)aKey" that merely call the relevent methods of the
class's member dictionary.
And that's it. All the other methods of NSDictionary are layered on top
of those three primary methods. You don't need to fool about with
forward invocations.
If you want to subclass NSMutableDictionary do the same thing but
provide implementations of "- (void)removeObjectForKey:(id)aKey" and "-
(void)setObject:(id)anObject forKey:(id)aKey" too.
See
http://developer.apple.com/documentation/Cocoa/Conceptual/Foundation/
Concepts/ClassClusters.html for more information (the example on that
page shows you how to subclass NSArray).
Jon.
On Dec 16, 2003, at 11:17, John Timmer wrote:
>
A while back I found out that subclassing a dictionary is a nightmare,
>
because dictionaries are actually one of a number of private
>
subclasses.
>
Categories won't work, since I still need a couple of additional
>
variables.
>
>
I was thinking that simply wrapping a dictionary in a class with a
>
forwardInvocation method would allow me send any messages I don't
>
understand
>
on to the dictionary, while still having a few variables and a couple
>
of
>
specialized methods. Are there reasons or situations where this would
>
fail
>
while a normal dictionary wouldn't? Any advice or warnings?
>
>
Thanks,
>
>
JT
>
_______________________________________________
>
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.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.