ActionKit is a experimental, 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.
Licensed under the terms of the MIT license
button.addTarget(self, action: Selector("buttonWasTapped:"), forControlEvents: .TouchUpInside)
func buttonWasTapped(sender: UIButton!) {
self.button.setTitle("Button was tapped!", forState: .Normal)
}
button.addControlEvent(.TouchUpInside) { self.button.setTitle("Button was tapped!", forState: .Normal) }
- addControlEvent(controlEvents: UIControlEvents, closure: () -> ())
button.addControlEvent(.TouchUpInside) { self.button.setTitle("Button was tapped!", forState: .Normal) }
- removeControlEvent(controlEvents: UIControlEvents)
button.removeControlEvent(.TouchUpInside)
- init(actionClosure: () -> ())
var singleTapGestureRecognizer = UITapGestureRecognizer() { self.view.backgroundColor = UIColor.redColor() }
- addActionClosure(actionClosure: () -> ())
singleTapGestureRecognizer.addActionClosure() { self.view.backgroundColor = UIColor.blueColor() }
- removeActionClosure()
singleTapGestureRecognizer.removeActionClosure()
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.
- Adding and removing an action to concrete gesture-recognizer objects, eg. UITapGestureRecognizer, UISwipeGestureRecognizer
- Adding and removing an action for UIControl objects, eg. UIButton, UIView
- Adding and removing multiple actions for a single UIGestureRecognizer
- Adding and removing multiple actions for a single UIControl
- Better manage stored closures
ActionKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ActionKit', '~> 1.0'
- Add the following to your Cartfile:
github "ActionKit/ActionKit"
- Run
carthage update
- Add the framework as described in Carthage Readme