ReactiveCocoa/ReactiveCocoa — pull request #554 by kastiglione (2013-06-01 22:58:29+00:00)
Title: Signal for selector using forwarding

:warning: Not ready for merging :warning:

As brought to attention by @kkazuo in #488, `_objc_msgForward` might be a way to build a more flexible `-rac_signalForSelector:`, specifically signals for existing methods and signals for methods with varying signatures. Here's a proof of concept.

With this change, instead of defining a new method for the given selector, `-rac_signalForSelector:` will define or redefine the given selector to point to `_objc_msgForward` as its `IMP`. In the case of existing methods, the `IMP` associated with the given selector is used to create an alias of the given selector. This alias is used later to invoke the expected implementation.

Next, `-rac_signalForSelector:` will define `-forwardInvocation:`, which will `-sendNext:` a tuple of the invocation's arguments, which is built using `NSInvocation(RACTypeParsing)`.

Finally, if `rac_signalForSelector:` was replacing an existing method, that method is invoked by changing the invocation's selector to the alias previously created.

With this implementation, it would be easy to add a signal that sends the return values from a method.