Skip to content

Extensions which helps to convert swifty closure to objc-style target/action

License

Notifications You must be signed in to change notification settings

kotalab/ActionClosurable

 
 

Repository files navigation

ActionClosurable

[![CI Status](http://img.shields.io/travis/Yoshitaka Seki/ActionClosurable.svg?style=flat)](https://travis-ci.org/Yoshitaka Seki/ActionClosurable) Version License Platform Carthage Compatible

Usage

ActionClosurable extends UIControl, UIButton, UIGestureRecognizer, UIBarButtonItem and NSTimer. It helps writing swifty code with closure, instead of target and action like below:

// UIControl
button.on(.TouchDown) {
    $0.backgroundColor = UIColor.redColor()
}
button.on(.TouchUpOutside) {
    $0.backgroundColor = UIColor.whiteColor()
}
// UIButton
button.onTap {
    $0.enabled = false
}

// UIGestureRecognizer
label.addGestureRecognizer(UIPanGestureRecognizer { gr in
    print("UIPanGestureRecognizer fire")
})

// UIBarButtonItem
let barButtonItem = UIBarButtonItem(title: "title", style: .Plain, closure: { _ in
    print("barButtonItem title")
})

// NSTimer
var i = 5
self.timer = NSTimer.scheduledTimerWithTimeInterval(1, repeats: true) { [weak self] timer in
    print("timer", i)
    i -= 1
    if i <= 0 {
        timer.invalidate()
        self?.timer = nil
    }
}

// And you can easily extend any NSObject subclasses!

And you can extend any NSObject subclasses in very easy way. Refer to the source.

Installation

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

pod "ActionClosurable"

ActionClosurable is available through Carthage. To install it, simply add the following line to your Cartfile:

github "takasek/ActionClosurable"

Author

takasek

License

ActionClosurable is available under the MIT license. See the LICENSE file for more info.

About

Extensions which helps to convert swifty closure to objc-style target/action

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 85.1%
  • Ruby 10.4%
  • Objective-C 4.5%