Code Monkey home page Code Monkey logo

actionkit's Introduction

ActionKit

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

Target-action example without ActionKit

button.addTarget(self, action: Selector("buttonWasTapped:"), forControlEvents: .TouchUpInside)
func buttonWasTapped(sender: UIButton!) {

    self.button.setTitle("Button was tapped!", forState: .Normal)
    
}

Target-action example with ActionKit

button.addControlEvent(.TouchUpInside) { self.button.setTitle("Button was tapped!", forState: .Normal) }

Methods

UIControl

Adding an action closure for a control event

- addControlEvent(controlEvents: UIControlEvents, closure: () -> ())
Example
button.addControlEvent(.TouchUpInside) { self.button.setTitle("Button was tapped!", forState: .Normal) }

Removing an action closure for a control event

- removeControlEvent(controlEvents: UIControlEvents)
Example
button.removeControlEvent(.TouchUpInside)

UIGestureRecognizer

Initializing a gesture recognizer with an action closure

- init(actionClosure: () -> ())
Example
var singleTapGestureRecognizer = UITapGestureRecognizer() { self.view.backgroundColor = UIColor.redColor() }

Adding an action closure to a gesture recognizer

- addActionClosure(actionClosure: () -> ())
Example
singleTapGestureRecognizer.addActionClosure() { self.view.backgroundColor = UIColor.blueColor() }

Removing an action closure for a control event

- removeActionClosure()
Example
singleTapGestureRecognizer.removeActionClosure()

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.

Supported

  • Adding and removing an action to concrete gesture-recognizer objects, eg. UITapGestureRecognizer, UISwipeGestureRecognizer
  • Adding and removing an action for UIControl objects, eg. UIButton, UIView

In the pipeline

  • Adding and removing multiple actions for a single UIGestureRecognizer
  • Adding and removing multiple actions for a single UIControl
  • Better manage stored closures

Installation

Carthage

  1. Add the following to your Cartfile:
    github "ActionKit/ActionKit"
  2. Run carthage update
  3. Add the framework as described in Carthage Readme

actionkit's People

Contributors

coolbnjmn avatar irlabs avatar mattijsf avatar thisiskevinchoi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.