ActionKit is a light-weight, easy to use framework that wraps the target-action design paradigm into a less verbose, cleaner format. It shortens target-action method calls by removing the target and replacing the selector with a closure.
button.addTarget(self, action: #selector(MyViewController.buttonWasTapped(_:)), forControlEvents: .TouchUpInside)
func buttonWasTapped(sender: Any) {
if let button = sender as? UIButton {
button.setTitle("Button was tapped!", forState: .Normal)
}
}
button.addControlEvent(.touchUpInside) { (control: UIControl) in
guard let button = control as? UIButton else {
return
}
button.setTitle("Button was tapped!", forState: .Normal)
}
ActionKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ActionKit', '~> 2.5.2'
github "ActionKit/ActionKit" == 2.5.2
carthage update
ActionKit extends target-action functionality by providing easy to use methods that take closures instead of a selector. ActionKit uses a singleton which stores the closures and acts as the target. Closures capture and store references to any constants and variables from their context, so the user is free to use variables from the context in which the closure was defined in.
UIGestureRecognizer
subclass (eg. UITapGestureRecognizer
, UIPanGestureRecognizer
...) instead of needing to use the target-action mechanismUIGestureRecognizer
subclassesUIControl
subclass (eg: UIButton
, UIView
, UISwitch
...) instead of needing to use the target-action mechanismUIControl
s, add an action for any number of controlEvent
sUIControl
subclassesUIBarButtonItem
, instead of needing target-actionUIBarButtonItem
sSee the examples wiki
See the changelog here
Licensed under the terms of the MIT license. See LICENSE file
link |
Stars: 254 |
Last commit: 4 years ago |
This release simply adds support for SPM!
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics