-
Notifications
You must be signed in to change notification settings - Fork 0
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
Delegate methods #42
Comments
It will take time to get used to it, but I like the idea. |
This reads better. But I think you mean func didSelect(item: Item, in spot: Spotable) |
@onmyway133 correct :) I'll fix it! |
Oh I see, can you change the label to call it something else than public protocol BarcodeScannerDismissalDelegate: class {
func didDismiss(barcodeScanner: BarcodeScannerController)
} |
@zenangst It will solve the problem, but I still find this naming a bit confusing. For example: // Old way:
protocol AdminHeaderViewDelegate: class {
func adminHeaderViewDidExpand(_ adminHeaderView: AdminHeaderView)
}
delegate?.adminHeaderViewDidExpand(self)
// New way, option 1:
protocol AdminHeaderViewDelegate: class {
func didExpand(adminHeaderView: AdminHeaderView)
}
delegate?.didExpand(adminHeaderView: self)
// New way, option 2
// Those 2 delegate methods make more sense, but are conflicting for compiler:
protocol AdminHeaderViewDelegate: class {
func didExpand(in adminHeaderView: AdminHeaderView)
}
protocol AdminFooterViewDelegate: class {
func didExpand(in adminFooterView: AdminFooterView)
} Also when I type |
I like |
Also in the example above it's |
Really interesting idea! 🤔 But I agree with @vadymmarkov, it does make it a bit hard to find the API that you're looking for. It also reduces API discoverability and makes it harder to know where a method "comes from" when implemented. Finally, it would make our code not inline with Apple's naming conventions (if this is something that's important to us, which at least for Open Source, I personally think it should be) 😅 The nice thing about always using the class name as a prefix for the delegate method names is that things are crystal clear. There are also ways to make the APIs nicer without removing the prefix naming. In the example given in the first post func spot(_ spot: Spotable, itemSelected item: Item) What do you guys think about that? 😄 |
I like this, we should update the public API's for frameworks such as Spots to be more scope with relevant prefixes. I guess that could go into the |
The methods in question here ended up looking like this: func spotable(_ spot: Spotable, itemSelected item: Item)
func spotablesDidChange(_ spots: [Spotable])
func spotable(_ spot: Spotable, willDisplay view: SpotView, item: Item)
func spotable(_ spot: Spotable, didEndDisplaying view: SpotView, item: Item) |
It got a bit inspired by http://khanlou.com/2016/09/swifty-delegates/ that @onmyway133 shared in the previous discussion. So I wanted to run some stuff by you when building delegate methods.
I would propose that we start moving towards what the article is describing.
To give you a concrete example from the Spots Swift 3 migration.
I'd like to change the public API for the
SpotsDelegate
method that gets invoked whenever someone taps on an item.Before
After
I think that reads much nicer.
What do you guys think? @hyperoslo/ios
The text was updated successfully, but these errors were encountered: