Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selector Signal Interoperability. #33

Closed
wants to merge 16 commits into from
Closed

Conversation

andersio
Copy link
Member

@andersio andersio commented Nov 12, 2016

Included test cases from #27.

Terminology

Stated class: The class the instance meant to be at compile time.
Runtime subclass: The subclass of the perceived class created at runtime.

Summary

RAC now respects any further swizzling of forwardInvocation:, responseToSelector: and method implementations made to the stated class.

The PR also fixed a bug that caused an unrecognised selector exception when calling a setter that has been swizzled by KVO and subsequently by RAC.

Implementation Notes

Before the PR, RAC grabs the IMP of any selector by searching through the inheritance hierarchy, and aliases it or preserves it before replacing the IMP with _objc_msgForward or its custom implementation.

After the PR, RAC generally does not alias any IMP, and relies on the ObjC runtime at the call time to resolve & call the method with an IMP swapping trick.

What's not solved

Interoperability with frameworks (except Cocoa KVO) that isa-swizzle an instance and provide custom implementations for the following selectors in the runtime subclass: forwardInvocation:, methodSignatureForSelector:, and respondsToSelector:.

Related: ReactiveCocoa/ReactiveCocoa#1561

@andersio andersio closed this Nov 12, 2016
@andersio andersio reopened this Nov 13, 2016
IMP impl = method_getImplementation(method);

if (impl != _objc_msgForward) {
class_replaceMethod(object_getClass(self), aliasSelector, impl, method_getTypeEncoding(method));
Copy link
Member Author

@andersio andersio Nov 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nasty, but there is no other reliable way to invoke a specific IMP with NSInvocation in the standard toolbox.

@andersio
Copy link
Member Author

andersio commented Nov 13, 2016

Hmm, not ready yet. Had a problem with KVO.

master actually fails if you swizzle an instance with KVO and then RAC. Probably due to the selector having a prefix.

Swift PR: ReactiveCocoa/ReactiveCocoa#3302
1. Improved performance in general method interception.
2. Reduced the overhead of computing selector aliases.
3. Reliable invocation of the next implementation of `-forwardInvocation:`, `-methodSignatureForSelector:` and `-respondsToSelector:` in the superclass hierarchy.
@andersio andersio force-pushed the selector-signal-interop branch from 596b3fa to 4dac92c Compare November 19, 2016 20:55
@bobspryn
Copy link
Contributor

What's the state of this PR?

@doggy
Copy link

doggy commented Feb 2, 2017

@sprynmr Still working in testing progress

@andersio
Copy link
Member Author

andersio commented Feb 2, 2017

Gonna port back a few changes from the Swift version.

@andersio andersio closed this Dec 23, 2017
byohay pushed a commit to byohay/ReactiveObjC that referenced this pull request Dec 14, 2021
…-latest-complete-if-no-inner-signal-is-sent

RACSignal+Operations: make -switchToLatest complete in all scenarios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants