Coder Social home page Coder Social logo

onmyway133 / easyclosure Goto Github PK

View Code? Open in Web Editor NEW
201.0 7.0 12.0 1.18 MB

🍩 Unified communication patterns with easy closure in Swift

Home Page: https://onmyway133.github.io/

License: Other

Objective-C 3.30% Ruby 6.19% Swift 90.51%
swift target action closure on

easyclosure's Introduction

EasyClosure

❤️ Support my apps ❤️

❤️❤️😇😍🤘❤️❤️

Version Carthage Compatible License Platform Swift

Table of contents

Story

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

Features

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

Example

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

UIButton

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

UISlider

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

UITextField

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

UITextView

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

UISearchBar

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

UIDatePicker

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

UIBarButtonItem

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

UIGestureRecognizer

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

Extensible

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
  
}

Installation

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.

Author

Khoa Pham, [email protected]

Contributing

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

License

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

easyclosure's People

Contributors

onmyway133 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

easyclosure's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.