<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sat, 06 Jun 2026 20:18:59 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Dmitri Kozlov - 2013-04-18 08:28:22</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Mike, that is a very helpful post.
&lt;br /&gt;I put together a proxy class implementation for iOS 6.0 SLComposeViewController class. It demonstrates a complete proxy code that forwards both instance and class methods and allows to use the new API on earlier versions of iOS.
&lt;br /&gt;&lt;a href="https://github.com/dmitrikozlov/MJSocialComposeViewController"&gt;https://github.com/dmitrikozlov/MJSocialComposeViewController&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;Hopefully someone will find it useful.
&lt;br /&gt;</description><guid isPermaLink="true">e981475253b9049a33ce3c7ba8289de3</guid><pubDate>Thu, 18 Apr 2013 08:28:22 GMT</pubDate></item><item><title>Denis - 2012-03-02 04:12:55</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Thank you, Mike! 
&lt;br /&gt;I've actually did it when read about meta-class, just after i asked this question. Objective-C doesn't stop to surprise me! </description><guid isPermaLink="true">f2400104f1ede7c0114f6d10d90def6d</guid><pubDate>Fri, 02 Mar 2012 04:12:55 GMT</pubDate></item><item><title>mikeash - 2012-03-01 20:34:57</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>I believe you can simply implement the forwarding methods as class methods and they will work to intercept messages sent to the class.</description><guid isPermaLink="true">7e470bdfa8cf27419afb24990401de60</guid><pubDate>Thu, 01 Mar 2012 20:34:57 GMT</pubDate></item><item><title>Denis - 2012-03-01 19:57:48</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Hi!
&lt;br /&gt;
&lt;br /&gt;Is there any way to forward class message to object? For example 
&lt;br /&gt;+ [MyClass test]  should be forwarded to - [someObject test].
&lt;br /&gt;
&lt;br /&gt;What i'm actually trying to implement is singleton with useful class methods declared in protocol, and if user send class message it should be forwarded to shared instance.
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">642ba6233be3ae446acf734026b6677b</guid><pubDate>Thu, 01 Mar 2012 19:57:48 GMT</pubDate></item><item><title>Peter N Lewis - 2011-09-28 02:08:01</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Thanks for a great article Mike!  forwardingTargetForSelector is very useful for the normal forwarding case, and I'm using it now to insert a delegate object to handle normal behaviour and pass on unused delegate messages to a user supplied delegate.
&lt;br /&gt;
&lt;br /&gt;One thing to clarify is that you also need to implement respondsToSelector, especially in the case of a delegate where the methods safe generally optional.  If you don't implement respondsToSelector, the caller will not try to execute the forwarded methods.</description><guid isPermaLink="true">b3bf616e99a0b4dfb33a755bc32b91b0</guid><pubDate>Wed, 28 Sep 2011 02:08:01 GMT</pubDate></item><item><title>mikeash - 2011-06-11 20:38:07</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>To my knowledge, @dynamic uses lazy method resolution with a great deal of internal trickery which allows it to bypass the slower but easier-to-deal-with normal forwarding path.</description><guid isPermaLink="true">a239bfdc7d53232a5a8480568e3c88d7</guid><pubDate>Sat, 11 Jun 2011 20:38:07 GMT</pubDate></item><item><title>Pitiphong Phongpattranont - 2011-06-06 10:44:58</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>What method do you think apple use in the @dynamic properties declaration in the CoreData framework?</description><guid isPermaLink="true">72e954433413e429a81d7a5221ff4d59</guid><pubDate>Mon, 06 Jun 2011 10:44:58 GMT</pubDate></item><item><title>mikeash - 2009-03-29 08:25:42</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>The best way to generate an NSMethodSignature is to get one with an NSObject method. Generally you will know what kind of signature you want when you write the code, so you can just write a little stub method (if you don't have a "real" one available) and then ask the object or class for the method signature for that method.
&lt;br /&gt;
&lt;br /&gt;I don't see where Apple says that type encodings can change. Generally, if they give a list like that, they mean for it to be something you can rely on. More concretely, since these strings get generated by the compiler and hardcoded into the binary, it would be impossible for them to make changes without destroying all sorts of existing stuff.</description><guid isPermaLink="true">513aaf6cc0816d9181b25e5cd7525586</guid><pubDate>Sun, 29 Mar 2009 08:25:42 GMT</pubDate></item><item><title>Vasi - 2009-03-28 06:45:39</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Is there any portable way to generate NSMethodSignatures? You can get one using a type encoding[1], but I'm under the impression Apple doesn't guarantee that the type encoding will always stay the same.
&lt;br /&gt;
&lt;br /&gt;[1] &lt;a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html"&gt;http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html&lt;/a&gt;</description><guid isPermaLink="true">e0a17a8ee8575ca97a6b5b68a3d3d0c7</guid><pubDate>Sat, 28 Mar 2009 06:45:39 GMT</pubDate></item><item><title>Matt Gallagher - 2009-03-28 06:35:54</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Mike, your posts continue to be great. I would never have seen forwardingTargetForSelector: if you hadn't pointed it out.
&lt;br /&gt;
&lt;br /&gt;Sijmen, there are lots of common code examples that use the method forwarding system to record methods in NSInvocations (to "forward" them later).
&lt;br /&gt;
&lt;br /&gt;The NSUndoManager does this to record undo invocations. I wrote a post a while ago on how you can do this in your own code: &lt;a href="http://cocoawithlove.com/2008/03/construct-nsinvocation-for-any-message.html"&gt;http://cocoawithlove.com/2008/03/construct-nsinvocation-for-any-message.html&lt;/a&gt;</description><guid isPermaLink="true">266119f7115db5e79840bc3a830c261e</guid><pubDate>Sat, 28 Mar 2009 06:35:54 GMT</pubDate></item><item><title>Sijmen - 2009-03-28 01:52:26</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Steve, that's a great idea.
&lt;br /&gt;
&lt;br /&gt;Anyone else tried something similar? I'm interested in any experiences with that approach.
&lt;br /&gt;
&lt;br /&gt;Great article btw.</description><guid isPermaLink="true">8d0c754368892b46605ddb18bb415158</guid><pubDate>Sat, 28 Mar 2009 01:52:26 GMT</pubDate></item><item><title>Steve - 2009-03-28 01:21:07</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html#comments</link><description>Message forwarding is a great feature of Objective-C, and lets you do some bizarre but useful stuff. One way I've used runtime proxies is in building an object editor with OK/cancel.
&lt;br /&gt;
&lt;br /&gt;Let's say that, in my app, the user wants to edit one of his Whizbang objects. In my editing controller, I'll create one of these proxy objects, and point it at the Whizbang he's editing. Then, I bind my interface to the proxy object, not the Whizbang. The editor proxy will then use KVC/KVO to "pull through" values from the Whizbang. If the user makes any changes, those are stored within the proxy. If the user clicks Cancel, those values are blown away. If the user clicks OK, the proxy iterates through its changes and sets the values on the Whizbang.
&lt;br /&gt;
&lt;br /&gt;This eliminates glue code, ties in automatically with the undo manager, etc. It's fantastic.</description><guid isPermaLink="true">78eae8834691776d3b95ba7232e33d1c</guid><pubDate>Sat, 28 Mar 2009 01:21:07 GMT</pubDate></item></channel></rss>
