• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mutable and immutable class cluster implementation / "method swizzling" question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Mutable and immutable class cluster implementation / "method swizzling" question (From: John Engelhart <email@hidden>)
 >Re: Mutable and immutable class cluster implementation / "method swizzling" question (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Mutable and immutable class cluster implementation / "method swizzling" question
  • Next by Date: Filter effects outside a CALayer
  • Previous by thread: Re: Mutable and immutable class cluster implementation / "method swizzling" question
  • Next by thread: Re: Mutable and immutable class cluster implementation / "method swizzling" question
  • Index(es):
    • Date
    • Thread