-
Notifications
You must be signed in to change notification settings - Fork 3
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
FunctionalHandler API Design #1
Comments
For now, the main way to use // Internal site
public class TapGestureRecognizer: UITapGestureRecognizer {
@FunctionalHandler<TapGestureRecognizer, Void>
var onTapGesture
init() {
super.init(target: nil, action: nil)
commonInit()
}
override public init(target: Any?, action: Selector?) {
super.init(target: target, action: action)
commonInit()
}
private func commonInit() {
self.addTarget(self, action: #selector(handleTap))
}
@objc private func handleTap(_ recognizer: TapGestureRecognizer) {
$onTapGesture?(recognizer)
}
} // Public site
func example() {
let tapRecognizer = TapGestureRecognizer()
tapRecognizer.onTapGesture { recognizer in
guard recognizer.state == .ended else { return }
print("tapped")
}
} But also I'd like to add // Public site
func example() {
let tapRecognizer = TapGestureRecognizer()
tapRecognizer.onTapGesture.scope(\.state) { state in
guard state == .ended else { return }
print("tapped")
}
} And the main reason for the discussion is the @FunctionalHandler<Void, Int>
var getNumberOfCells func hideHalfOfCells() {
getNumberOfCells.map { $0 / 2 }
} But |
|
Also |
|
Swift 5.9 introduced variadic generics, which may allow us to get rid of generic type overloads, but currently it's only supported on iOS17+ for types, maybe we may consider using macros to support it across all oss 🤔 |
A place to discuss FunctionalHandler API
The text was updated successfully, but these errors were encountered: