https://github.com/hhru/handlerskit
HandlersKit is a light-weight iOS Framework that allows you to use modern closure syntax instead of the target-action and delegate patterns
https://github.com/hhru/handlerskit
ios swift uikit
Last synced: 5 months ago
JSON representation
HandlersKit is a light-weight iOS Framework that allows you to use modern closure syntax instead of the target-action and delegate patterns
- Host: GitHub
- URL: https://github.com/hhru/handlerskit
- Owner: hhru
- License: mit
- Created: 2020-02-12T15:06:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-17T06:08:05.000Z (about 2 years ago)
- Last Synced: 2024-10-29T03:17:25.834Z (6 months ago)
- Topics: ios, swift, uikit
- Language: Swift
- Homepage:
- Size: 44.9 KB
- Stars: 34
- Watchers: 7
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HandlersKit
[](https://github.com/hhru/HandlersKit/actions)
[](https://codecov.io/gh/hhru/HandlersKit)
[](http://cocoapods.org/pods/HandlersKit)
[](https://github.com/Carthage/Carthage)
[](https://swift.org/package-manager/)
[](https://developer.apple.com/xcode)
[](https://swift.org)
[](https://opensource.org/licenses/MIT)HandlersKit is a light-weight iOS Framework that allows you to use modern closure syntax instead of the target-action and delegate patterns. This framework covers the most popular UIKit classes.
## Overview
Closure syntax instead of [UIControl's](https://developer.apple.com/documentation/uikit/uicontrol) target-action mechanism.
```swift
control.on(.valueChanged) {
print("UIControl's value changed")
}
```
---
Convenient methods for the most common cases.
```swift
button.onTap {
print("UIButton touch up inside")
}
```
```swift
slider.onChange { newValue in
print("UISlider changed value")
}
```
---
Access to the same object inside the closure without typecasting or optional unwrapping.
```swift
let button = MyActivityIndicatorButton()
button.onTap { (sender: MyActivityIndicatorButton) in
sender.showActivityIndicator()
}
```
---
Every method allows [chaining](https://en.wikipedia.org/wiki/Method_chaining).
```swift
textField.shouldChangeString { fromString, toString in
print("\(fromString) -> \(toString)")
return true
}.shouldBeginEditing {
true
}.didEndEditing {
print("UITextField did end editing")
}
```## Benefits
- HandlersKit extends [UIControl](https://developer.apple.com/documentation/uikit/uicontrol), [UIBarButtonItem](https://developer.apple.com/documentation/uikit/uibarbuttonitem), [UIGestureRecognizer](https://developer.apple.com/documentation/uikit/uigesturerecognizer), [UITextField](https://developer.apple.com/documentation/uikit/uitextfield) and [UITextView](https://developer.apple.com/documentation/uikit/uitextview).
- Closures stored as associated objects. No singleton or Notification Center used. It means that all objects captured by this closure will be released when that UIKit object released.## Requirements
- iOS 12.0+ / tvOS 12.0+
- Xcode 13.0+
- Swift 5.5+## Installation
### CocoaPods
To install HandlersKit using [CocoaPods](http://cocoapods.org) add the following line to your `Podfile`:
```ruby
pod 'HandlersKit'
```
Then run in Terminal:
```sh
$ pod install
```### Carthage
To integrate HandlersKit into your project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile:
```shell
github "hhru/HandlersKit"
```### Swift Package Manager
To integrate HandlersKit into your project using [Swift Package Manager](https://swift.org/package-manager/), you have two different ways:
1. In Xcode, go to `File > Swift Packages > Add Package Dependency...` and enter the following URL:
```
https://github.com/hhru/HandlersKit
```
2. Or add the following as a dependency to your `Package.swift`:
```swift
.package(url: "https://github.com/hhru/HandlersKit.git", from: "1.2.0")
```### Manual
- Go to [releases page](https://github.com/hhru/HandlersKit/releases).
- Download the latest release `Source code`.
- Drag and drop all .swift files from `HandlersKit-x.y.z/Sources` folder into your Xcode project. Check the option *Copy items if needed*.## License
HandlersKit is released under the MIT License. (see [LICENSE](https://github.com/hhru/HandlersKit/blob/master/LICENSE)).