<commit_before>//
//  UIControl+Actionable.swift
//
//  Created by <NAME> on 6/22/16.
//
// The MIT License (MIT)
//
// Copyright (c) 2014-2016 Oven Bits, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

protocol Actionable: NSObjectProtocol {
    
    init(actionClosure: (Self) -> Void)
    init(frame: CGRect, actionClosure: (Self) -> Void)
    func addTarget(controlEvents controlEvents: UIControlEvents, actionClosure: (Self) -> Void)
    
}

extension Actionable where Self : UIControl {
    
    private var action: Action<Self>? {
        set { objc_setAssociatedObject(self, &AssociatedKeys.ActionName, newValue, .OBJC_ASSOCIATION_RETAIN) }
        get { return objc_getAssociatedObject(self, &AssociatedKeys.ActionName) as? Action }
    }
    
    /**
     Initialize a UIControl, using the given closure as the .TouchUpInside target/action event.
     
     - parameter action: The closure to execute upon control press.
     
     - returns: An initialized UIControl.
     */
    init(actionClosure: (Self) -> Void) {
        self.init()
        action = Action(action: actionClosure)
        addTarget(self, action: #selector(handleAction), forControlEvents: .TouchUpInside)
    }
    
    
    /**
     Initialize a UIControl with the given frame, using the given closure as the .TouchUpInside target/action event.
     
     - parameter frame:  The frame of the control.
     - parameter action: the closure to execute upon control press.
     
     - returns: An initialized UIControl.
     */
    init(frame: CGRect, actionClosure: (Self) -> Void) {
        self.init(frame: frame)
        action = Action(action: actionClosure)
        addTarget(self, action: #selector(handleAction), forControlEvents: .TouchUpInside)
    }
    
    
    /**
     Adds the given closure as the control's target action
     
     - parameter controlEvents: The UIControlEvents upon which to execute this action.
     - parameter action:        The action closure to execute.
     */
    func addTarget(controlEvents controlEvents: UIControlEvents, actionClosure: (Self) -> Void) {
        action = Action(action: actionClosure)
        addTarget(self, action: #selector(handleAction), forControlEvents: controlEvents)
    }
}

private class Action<T: ActionSelectable> {
    var action: (T) -> Void
    
    init(action: (T) -> Void) {
        self.action = action
    }
}<commit_msg>Make things public<commit_after>//
//  UIControl+Actionable.swift
//
//  Created by <NAME> on 6/22/16.
//
// The MIT License (MIT)
//
// Copyright (c) 2014-2016 Oven Bits, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

public protocol Actionable: NSObjectProtocol {
    
    init(actionClosure: (Self) -> Void)
    init(frame: CGRect, actionClosure: (Self) -> Void)
    func addTarget(controlEvents controlEvents: UIControlEvents, actionClosure: (Self) -> Void)
    
}

public extension Actionable where Self : UIControl {
    
    private var action: Action<Self>? {
        set { objc_setAssociatedObject(self, &AssociatedKeys.ActionName, newValue, .OBJC_ASSOCIATION_RETAIN) }
        get { return objc_getAssociatedObject(self, &AssociatedKeys.ActionName) as? Action }
    }
    
    /**
     Initialize a UIControl, using the given closure as the .TouchUpInside target/action event.
     
     - parameter action: The closure to execute upon control press.
     
     - returns: An initialized UIControl.
     */
    public init(actionClosure: (Self) -> Void) {
        self.init()
        action = Action(action: actionClosure)
        addTarget(self, action: #selector(handleAction), forControlEvents: .TouchUpInside)
    }
    
    
    /**
     Initialize a UIControl with the given frame, using the given closure as the .TouchUpInside target/action event.
     
     - parameter frame:  The frame of the control.
     - parameter action: the closure to execute upon control press.
     
     - returns: An initialized UIControl.
     */
    public init(frame: CGRect, actionClosure: (Self) -> Void) {
        self.init(frame: frame)
        action = Action(action: actionClosure)
        addTarget(self, action: #selector(handleAction), forControlEvents: .TouchUpInside)
    }
    
    
    /**
     Adds the given closure as the control's target action
     
     - parameter controlEvents: The UIControlEvents upon which to execute this action.
     - parameter action:        The action closure to execute.
     */
    public func addTarget(controlEvents controlEvents: UIControlEvents, actionClosure: (Self) -> Void) {
        action = Action(action: actionClosure)
        addTarget(self, action: #selector(handleAction), forControlEvents: controlEvents)
    }
}

private class Action<T: ActionSelectable> {
    var action: (T) -> Void
    
    init(action: (T) -> Void) {
        self.action = action
    }
}
{'fraction_non_alphanumeric': 0.08760186263096624, 'fraction_numerical': 0.0037834691501746217, 'mean_word_length': 3.0668639053254436, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '2117132', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1830, 'n_words': 725}