<commit_before><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" align="right" vspace="2px">

# 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 (prior to Swift 2.2)
```swift
button.addTarget(self, action: Selector("buttonWasTapped:"), forControlEvents: .TouchUpInside)
```

```swift
func buttonWasTapped(sender: UIButton!) {

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

## Target-action example without ActionKit with Swift 2.2

```swift
button.addTarget(self, action: #selector(ViewController.buttonWasTapped(_:)), forControlEvents: .TouchUpInside)
```

```swift
func buttonWasTapped(sender: UIButton!) {

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

## Target-action example with ActionKit

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

}
```

## Target-action example with ActionKit with closure parameter

```swift
button.addControlEvent(.TouchUpInside) { (control: UIControl) in
  
  if let theButton = control as? UIButton {
    theButton.setTitle("Button was tapped!", forState: .Normal)
  }

}
```

## Methods

### UIControl

#### Adding an action closure for a control event

```swift
- addControlEvent(controlEvents: UIControlEvents, closure: () -> ())

- addControlEvent(controlEvents: UIControlEvents, closureWithControl: (UIControl) -> ())
```

##### Examples

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

}
```

```swift
button.addControlEvent(.TouchUpInside) { (control: UIControl) in
  
  if let theButton = control as? UIButton {
    theButton.setTitle("Button was tapped!", forState: .Normal)
  }

}
```

#### Removing an action closure for a control event

```swift
- removeControlEvent(controlEvents: UIControlEvents)
```

##### Example

```swift
button.removeControlEvent(.TouchUpInside)
```

### UIGestureRecognizer

#### Initializing a gesture recognizer with an action closure

```swift
- init(closure: () -> ())

- init(closureWithGesture: (UIGestureRecognizer) -> ())
```

##### Examples

```swift
var singleTapGestureRecognizer = UITapGestureRecognizer() {
  
  self.view.backgroundColor = UIColor.redColor()

}
```

```swift
var singleTapGestureRecognizer = UITapGestureRecognizer() { (gesture: UIGestureRecognizer) in
  
  if gesture.state == .Began {
      let locInView = gesture.locationInView(self.view)<commit_msg>Update Readme to reflect use of Generic closure parameters<commit_after><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" align="right" vspace="2px">

# 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 (prior to Swift 2.2)
```swift
button.addTarget(self, action: Selector("buttonWasTapped:"), forControlEvents: .TouchUpInside)
```

```swift
func buttonWasTapped(sender: UIButton!) {

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

## Target-action example without ActionKit with Swift 2.2

```swift
button.addTarget(self, action: #selector(ViewController.buttonWasTapped(_:)), forControlEvents: .TouchUpInside)
```

```swift
func buttonWasTapped(sender: UIButton!) {

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

## Target-action example with ActionKit

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

}
```

## Target-action example with ActionKit with closure parameter

```swift
button.addControlEvent(.TouchUpInside) { (button: UIButton) in
  
  button.setTitle("Button was tapped!", forState: .Normal)

}
```

## Methods

### UIControl

#### Adding an action closure for a control event

```swift
- addControlEvent(controlEvents: UIControlEvents, closure: () -> ())

- addControlEvent(controlEvents: UIControlEvents, closureWithControl: (UIControl) -> ())
```

##### Examples

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

}
```

```swift
button.addControlEvent(.TouchUpInside) { (button: UIButton) in
  
    button.setTitle("Button was tapped!", forState: .Normal)

}
```

#### Removing an action closure for a control event

```swift
- removeControlEvent(controlEvents: UIControlEvents)
```

##### Example

```swift
button.removeControlEvent(.TouchUpInside)
```

### UIGestureRecognizer

#### Initializing a gesture recognizer with an action closure

```swift
- init(closure: () -> ())

- init(closureWithGesture: (UIGestureRecognizer) -> ())
```

##### Examples

```swift
var singleTapGestureRecognizer = UITapGestureRecognizer() {
  
  self.view.backgroundColor = UIColor.redColor()

}
```

```swift
var singleTapGestureRecognizer = UITapGestureRecognizer() { (gesture: UITapGestureRecognizer) in
  
  if gesture.state == .Began {
      let locInView = gesture.locationInView(self.view)
{'fraction_non_alphanumeric': 0.13702096890817064, 'fraction_numerical': 0.0028922631959508315, 'mean_word_length': 5.182122905027933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1807153', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1672, 'n_words': 431}