Giter VIP home page Giter VIP logo

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

actionkit's Projects

actionkit icon actionkit

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.