Rightpoint / ios-template

A `cookiecutter` template for iOS projects
MIT License
94 stars 26 forks source link

UIControl+Blocks #76

Closed heyltsjay closed 6 years ago

jvisenti commented 6 years ago

FWIW I'm against blockified UIControls

heyltsjay commented 6 years ago

your FWIW is definitely W

heyltsjay commented 6 years ago

Are you concerned about making ownership mistakes, deviating from UIKit, not enough of a win, all of the above?

jvisenti commented 6 years ago

Ownership mistakes yes (we both saw them come out of the woodwork on this last project), and not enough of a win. In fact, I think in many cases it harms readability over having a separate method. Stuff like this from that same recent project is an example of both:

button.callback = { [weak self, unowned button] in
    self?.notify(.action(from: button))
}

I made the same argument with RZDataBinding which is why that followed target/action paradigm.

heyltsjay commented 6 years ago

I'm pretty compelled by the happy path, where convenience methods can vend in weak closures

skipButton.callback = notify(.skip)

But I agree that things got pretty icky when multiple block-based APIs started nesting inside one another.

jvisenti commented 6 years ago

If you don't self?.notify(.skip) you've caused a retain cycle 😬 Edit: Oh you mean the extension on Actionable. Is that in the template?

heyltsjay commented 6 years ago

well, you're going to hate it but, no because of:

extension Actionable {

    func notify(_ action: ActionType) -> () -> Void {
        return { [weak self] in
            self?.notify(action)
        }
    }
heyltsjay commented 6 years ago

I think this conversation has convinced me that this doesn't need to go in. Easy enough for folks to pull in if they choose.