Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takasek/ActionClosurable
Extensions which helps to convert objc-style target/action to swifty closures
https://github.com/takasek/ActionClosurable
carthage closure cocoapods ios nsobject selector swift target-action
Last synced: about 1 month ago
JSON representation
Extensions which helps to convert objc-style target/action to swifty closures
- Host: GitHub
- URL: https://github.com/takasek/ActionClosurable
- Owner: takasek
- License: mit
- Created: 2016-04-16T09:27:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-08-13T13:47:15.000Z (over 5 years ago)
- Last Synced: 2024-11-18T03:13:39.645Z (about 2 months ago)
- Topics: carthage, closure, cocoapods, ios, nsobject, selector, swift, target-action
- Language: Swift
- Homepage:
- Size: 50.8 KB
- Stars: 124
- Watchers: 3
- Forks: 15
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - ActionClosurable - Extensions which helps to convert objc-style target/action to swifty closures. (Utility / Web View)
- awesome-ios-star - ActionClosurable - Extensions which helps to convert objc-style target/action to swifty closures. (Utility / Web View)
README
# ActionClosurable
[![Version](https://img.shields.io/cocoapods/v/ActionClosurable.svg?style=flat)](http://cocoapods.org/pods/ActionClosurable)
[![License](https://img.shields.io/cocoapods/l/ActionClosurable.svg?style=flat)](http://cocoapods.org/pods/ActionClosurable)
[![Platform](https://img.shields.io/cocoapods/p/ActionClosurable.svg?style=flat)](http://cocoapods.org/pods/ActionClosurable)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)## Usage
ActionClosurable extends `UIControl`, `UIButton`, `UIRefreshControl`, `UIGestureRecognizer` and `UIBarButtonItem`.
It helps writing swifty code with closure, instead of target and action like below:```swift
// UIControl
button.on(.touchDown) {
$0.backgroundColor = UIColor.redColor()
}
button.on(.touchUpOutside) {
$0.backgroundColor = UIColor.whiteColor()
}
// UIButton
button.onTap {
$0.enabled = false
}// UIRefreshControl
tableView.refreshControl = UIRefreshControl { refreshControl in
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
refreshControl.endRefreshing()
}
}// UIGestureRecognizer
label.addGestureRecognizer(UIPanGestureRecognizer { (gr) in
print("UIPanGestureRecognizer fire")
})// UIBarButtonItem
let barButtonItem = UIBarButtonItem(title: "title", style: .plain) { _ in
print("barButtonItem title")
}// And you can easily extend any NSObject subclasses!
```And you can extend any NSObject subclasses in very easy way. [Refer to the source.](https://github.com/takasek/ActionClosurable/blob/master/ActionClosurable/Extensions.swift)
## Installation
ActionClosurable is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "ActionClosurable"
```
ActionClosurable is available through [Carthage](https://github.com/Carthage/Carthage). To install it, simply add the following line to your Cartfile:```ruby
github "takasek/ActionClosurable"
```ActionClosurable is available through [Swift Package Manager](https://github.com/apple/swift-package-manager). To install it, add dependency in `Package.swift`:
```swift
let package = Package(
...
dependencies: [
.package(url: "[email protected]:takasek/ActionClosurable.git", from: "2.1.0"),
],
...
)
```## Author
[takasek](https://twitter.com/takasek)
## License
ActionClosurable is available under the MIT license. See the LICENSE file for more info.