ActionKit

Easy, closure-based Swift methods for working with interactive UIKit elements.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

255

Maintenance

Last Commit

2yrs ago

Contributors

20

Package

Dependencies

0

License

MIT

Categories

Readme

Banner Version Carthage License Platform Swift

ActionKit

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.

Example of target-action without ActionKit

button.addTarget(self, action: #selector(MyViewController.buttonWasTapped(_:)), forControlEvents: .TouchUpInside)

and somewhere else...

func buttonWasTapped(sender: Any) {
  if let button = sender as? UIButton {
    button.setTitle("Button was tapped!", forState: .Normal)
  } 
}

Or with ActionKit, all in one place

button.addControlEvent(.touchUpInside) { (control: UIControl) in
  guard let button = control as? UIButton else {
    return
  }
  button.setTitle("Button was tapped!", forState: .Normal)

}

Installation

CocoaPods

ActionKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ActionKit', '~> 2.5.2'

Carthage

    1. Add the following to your Cartfile:
    github "ActionKit/ActionKit" == 2.5.2

How it works

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.

Features

  • Add an action based closure to any UIGestureRecognizer subclass (eg. UITapGestureRecognizer, UIPanGestureRecognizer...) instead of needing to use the target-action mechanism
  • Remove actions added to UIGestureRecognizer subclasses
  • Add an action based closure to any UIControl subclass (eg: UIButton, UIView, UISwitch...) instead of needing to use the target-action mechanism
  • For UIControls, add an action for any number of controlEvents
  • Remove actions added to UIControl subclasses
  • Add an action based closure to any UIBarButtonItem, instead of needing target-action
  • Remove actions added to UIBarButtonItems

Examples

See the examples wiki

Changelog

See the changelog here

License

Licensed under the terms of the MIT license. See LICENSE file

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100