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

DelegateProxy revamp #3467

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

DelegateProxy revamp #3467

wants to merge 22 commits into from

Conversation

andersio
Copy link
Member

@andersio andersio commented May 27, 2017

  1. Methods would now be automatically implemented. Subclassing is no longer necessary.

  2. DelegateProxy can now be constructed through NSObject.reactive.proxy(forKey:).

  3. Fixed a memory leak due to the use of forwardingTarget(for:) as the fast path of delegate call forwarding.

  4. More DelegateProxy test cases.

Usage

extension Reactive where Base: UITableView {
    var proxy: DelegateProxy<UITableViewDelegate> {
        return proxy(forKey: #keyPath(UITableView.delegate))
    }
}

To-do

  • Evaluate the behaviour of protocols with non-void-returning required methods.
  • Documentations and Implementation Notes.
  • Share implementation with method Interception.

@andersio andersio force-pushed the delegate-proxy-revamp branch 7 times, most recently from 44f9f14 to 22d03c7 Compare May 27, 2017 19:02
@andersio andersio force-pushed the delegate-proxy-revamp branch 7 times, most recently from b18dff1 to 2646832 Compare May 28, 2017 15:38
@andersio andersio added this to the 6.0 milestone May 28, 2017
@andersio andersio force-pushed the delegate-proxy-revamp branch 10 times, most recently from 3305254 to b13fc84 Compare May 29, 2017 01:07
@andersio andersio modified the milestone: 6.0 Jun 9, 2017
@andersio andersio requested a review from mdiep October 22, 2017 10:19
@dmcrodrigues
Copy link
Contributor

@mdiep any chance of moving this forward?

@mdiep
Copy link
Contributor

mdiep commented Jan 6, 2019

Somehow I missed this. I just got back from vacation, but I'll this to my list. Want to fix up the conflicts, @andersio?

@andersio
Copy link
Member Author

Sure. Will do it this week.

ReactiveCocoa/DelegateProxy.swift Outdated Show resolved Hide resolved
private final let originalSetter: (AnyObject) -> Void
private final let objcProtocol: Protocol

public required init(config: DelegateProxyConfiguration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be public? Or should we only expose the proxy method below?

If this is public, should we inline the properties from DelegateProxyConfiguration in the init?

Copy link
Member Author

Choose a reason for hiding this comment

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

The initialiser is meant to be exposed, while the details of the configuration are meant to be hidden. This is to satisfy the compiler constraint of instantiating instances from the metatype of the non-final DelegateProxy, which requires init(DelegateProxyConfiguration) to be always present in all subclasses, so that the instantiation via the metatype always succeeds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is DelegateProxy non-final?

@andersio
Copy link
Member Author

andersio commented Feb 2, 2019

CI build might be affected by #3642.

fileprivate let originalSetter: (AnyObject) -> Void
}

public class DelegateProxy<Delegate: NSObjectProtocol>: NSObject, DelegateProxyProtocol {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't DelegateProxy be final?

Copy link
Member Author

@andersio andersio Mar 16, 2019

Choose a reason for hiding this comment

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

#3467 (comment)

But if you still think it is more sensible for us to start with final, I am fine with that.
Apparently I've already made it non-open. I guess the intention of not marking it as final is to avoid any library evolution implication — undoing final is not a permitted change.

Most importantly, this entity primarily interacts with ObjC which final has no effect, and being public already prohibits subclassing.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if we made it final, then we could make this method private? That seems worth doing

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep.

Copy link
Member Author

Choose a reason for hiding this comment

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

In any case I think intercepting non-void returning methods is probably very niche, and a rather dangerous zone to walk into with little return. So closing it should be fine.

@mdiep
Copy link
Contributor

mdiep commented Mar 20, 2019

Let's get this merged before doing a new release for ReactiveSwift 5.

The only outstanding question from me is this. If we can't do that, you're good to merge.

@mdiep
Copy link
Contributor

mdiep commented Mar 22, 2019

The tests need to be updated to not inherit from DelegateProxy now that it's final.

@mdiep
Copy link
Contributor

mdiep commented Mar 26, 2019

@andersio I'd like to release ReactiveCocoa 9.0. Still want to get this in?

@mdiep
Copy link
Contributor

mdiep commented Mar 31, 2019

It looks like there may still be some legitimate test failures?

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.

None yet

3 participants