-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Mutual exclusive delegate methods #1087
Comments
Hi @djmadcat , So if I understood you correctly, you are saying that
... and the same for |
This won't work on Deployment Target iOS versions prior to 10=( This will: public var didEndEditing: ControlEvent<()> {
if #available(iOS 10.0, *) {
return ControlEvent<()>(events: self.delegate.methodInvoked(#selector(UITextFieldDelegate.textFieldDidEndEditing(_:reason:)))
.map { _ in () })
} else {
return ControlEvent<()>(events: self.delegate.methodInvoked(#selector(UITextFieldDelegate.textFieldDidEndEditing(_:)))
.map { _ in () })
}
} But this solution is incompatible with iOS updates: application can't handle addition of new delegate method in new iOS version properly. It only knows about methods in SDK. I think there are two major problems:
So I see there two solutions:
|
Hi @djmadcat ,
I don't it's realistic to expect for this library to be bulletproof on major os updates.
The reason why this is the case is because delegate setter caches all selectors delegate responds to. We could theoretically solve this by resetting delegate each time number of observers goes from 0 to 1 or from 1 to 0 for a specific selector. The reason why this strategy wasn't chosen was because it seemed to me that setting delegate multiple times fast could cause glitches (especially for
Don't understand this one.
I'm not sure this would be a good idea, but maybe it is. I would need to test it more thoroughly.
I'm ok with documenting this behavior for now. Feel free to create a PR. We can investigate for 4.0 would resetting delegate proxies in fast succession cause any issues. |
Short description of the issue:
When a delegate implements a new version of the method, the old version is not called.
So when we use
func methodInvoked(_ selector: Selector) -> Observable<[Any]>
method to intercept older method, it does not invoked.Expected outcome:
Any method must be able to be intercepted.
What actually happens:
For example:
UITextFieldDelegate
has two versions fordidEndEditing
method:func textFieldDidEndEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason)
What happens:
Observable
by callingdelegate.methodInvoked(#selector(UITextFieldDelegate.textFieldDidEndEditing(_:)))
textFieldDidEndEditing:reason:
support by callingrespondsToSelector:
._RXDelegateProxy
collects allUITextFieldDelegate
methods and finds it.textFieldDidEndEditing:reason:
withforwardInvocation:
.textFieldDidEndEditing:
not being called.Self contained code example that reproduces the issue:
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
3.1.0
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
Installation method:
I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)
Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)
The text was updated successfully, but these errors were encountered: