Skip to content
🍩 Unified communication patterns with easy closure in Swift
Branch: master
Clone or download
Latest commit 97d5981 May 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
EasyClosure-tvOS Initial commit May 18, 2019
EasyClosure.xcodeproj Fix name for macOS May 18, 2019
EasyClosure Initial commit May 18, 2019
EasyClosureTests Add macOS tests May 18, 2019
Example/EasyClosureDemo Update readme May 18, 2019
Playground-Mac.playground Initial commit May 18, 2019
Screenshots Initial commit May 18, 2019
Sources Fix name for macOS May 18, 2019
.gitignore Initial commit May 18, 2019 Initial commit May 18, 2019
EasyClosure.podspec Fix name for macOS May 18, 2019 Initial commit May 18, 2019 Update May 21, 2019


Version Carthage Compatible License Platform Swift

Table of contents


There are many Communication patterns

Sometimes, you just want a unified and quick way to do it. Just call on on any NSObject subclasses and handle your events the quickest way


  • Shortcut to handle actions and events
  • Easy to extend
  • Correct method suggestion based on generic protocol constraint
  • Support iOS, macOS


We can make a fun demo of good, cheap, fast with UISwitch

func allOn() -> Bool {
  return [good, cheap, fast].filter({ $0.isOn }).count == 3

good.on.valueChange { _ in
  if allOn() {
    fast.setOn(false, animated: true)

cheap.on.valueChange { _ in
  if allOn() {
    good.setOn(false, animated: true)

fast.on.valueChange { _ in
  if allOn() {
    cheap.setOn(false, animated: true)

Target-Action and Delegate


button.on.tap {
  print("button has been tapped")


slider.on.valueChange { value in
  print("slider has changed value")


textField.on.textChange { text in
  print("textField text has changed")


textView.on.textChange { text in
  print("textView text has changed")


searchBar.on.textChange { text in
  print("searchBar text has changed")


datePicker.on.pick { date in
  print("datePicker has changed date")


barButtonItem.on.tap {
  print("barButtonItem has been tapped")


gestureRecognizer.on.occur {
  print("gesture just occured")


Extend Container and specify Host to add more functionalities to your own types. For example

public extension Container where Host: UITableView {
  func cellTap(_ action: @escaping (UITableViewCell) -> Void)) {
    // Your code here here

// usage
let tableView = UITableView()
tableView.on.cellTap { cell in


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

pod 'EasyClosure'

EasyClosure is also available through Carthage. To install just write into your Cartfile:

github "onmyway133/EasyClosure"

EasyClosure can also be installed manually. Just download and drop Sources folders in your project.


Khoa Pham,


We would love you to contribute to EasyClosure, check the CONTRIBUTING file for more info.


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

You can’t perform that action at this time.