Re: Mutable and immutable class cluster implementation / "method swizzling" question
Re: Mutable and immutable class cluster implementation / "method swizzling" question
- Subject: Re: Mutable and immutable class cluster implementation / "method swizzling" question
- From: Louis-Philippe <email@hidden>
- Date: Fri, 25 Mar 2011 08:09:47 -0400
An other totally different angle to tackle the implementation would be to
use both inheritance and proxing with forwardInvocation.
having:
(something like) MyObject as RootClass
then, MyArray subclass MyObject and forwardInvocation to an inner NSArray
ivar
and MyMutableArray subclass MyObject and forwardInvocation to an inner
NSMutableArray ivar
then essentially, your specific classes, MyArray and MyMutable array end up
implementing:
- (void)forwardInvocation:(NSInvocation *)invocation {
[invocation invokeWithTarget:innerArray];
}
- (BOOL)respondsToSelector:(SEL)aSelector {
if ([super respondsToSelector:aSelector]) {
return YES;
}
return [innerArray respondsToSelector:aSelector];
}
- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector
{
NSMethodSignature* signature = [super
methodSignatureForSelector:selector];
if (!signature) {
signature = [innerArray methodSignatureForSelector:selector];
}
return signature;
}
So every call goes first down the standard inheritance chain, if not, gets
forwarded to the proxied array.
I believe this implementation is easier than playing with the runtime
copying methods.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden