• 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: setValue:forKey: and invocation forwarding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setValue:forKey: and invocation forwarding


  • Subject: Re: setValue:forKey: and invocation forwarding
  • From: glenn andreas <email@hidden>
  • Date: Tue, 13 Jul 2010 08:56:06 -0500

On Jul 13, 2010, at 7:53 AM, Graham Cox wrote:

> It appears that calling -setValue:forKey: on an object bypasses or ignores any invocation forwarding it has set up, unless I'm missing some obvious error.
>
> I have an object that acts as a wrapper for another object, and so that the wrapper can, under some circumstances, act as the thing it is wrapping, it implements invocation forwarding using the 'classic' approach of overriding -respondsToSelector:, -methodSignatureForSelector: and -forwardInvocation: but when I call -setValue:forKey: on the wrapper (where key is implemented by the thing wrapped), it throws the 'not key-value coding compliant for key' exception. The stack trace appears to show that this failure occurs before it has even attempted to follow the forwarded path. However if I simply call the wrapped property setter directly, the forwarding works. As this needs to work on 10.5, I can't use the 10.6 solution of -forwardingTargetForSelector: (not that I've tested it to see if it exhibits the same issue or not).
>
> Is this the expected behaviour?

Well, the documentation (KVC Programming Guide, Accessor Search Implementation Details)  says that the pattern for setValue:forKey:

	• The receiver’s class is searched for an accessor method whose name matches the pattern -set<Key>:.

So the question is "what does 'searched' mean"?  Since that document talks about method names that match certain patterns, I'm guessing that it walks the method table (instead of calling respondsToSelector:).

I'd just override valueForKey: and setValue:forKey: in your class to handle forwarding those to your wrapped object.


Glenn Andreas                      email@hidden
The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL

_______________________________________________

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

  • Follow-Ups:
    • Re: setValue:forKey: and invocation forwarding
      • From: Graham Cox <email@hidden>
References: 
 >setValue:forKey: and invocation forwarding (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: setValue:forKey: and invocation forwarding
  • Next by Date: Re: setValue:forKey: and invocation forwarding
  • Previous by thread: Re: setValue:forKey: and invocation forwarding
  • Next by thread: Re: setValue:forKey: and invocation forwarding
  • Index(es):
    • Date
    • Thread