Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🍩 Unified communication patterns with easy closure in Swift

License

NotificationsYou must be signed in to change notification settings

onmyway133/EasyClosure

Repository files navigation

❤️ Support my apps ❤️

❤️❤️😇😍🤘❤️❤️

VersionCarthage CompatibleLicensePlatformSwift

Table of contents

Story

There are manyCommunication patterns

Sometimes, you just want a unified and quick way to do it. Just callon on anyNSObject 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 ofgood, cheap, fast withUISwitch

func allOn()->Bool{return[good, cheap, fast].filter({ $0.isOn}).count==3}good.on.valueChange{ _inifallOn(){    fast.setOn(false, animated:true)}}cheap.on.valueChange{ _inifallOn(){    good.setOn(false, animated:true)}}fast.on.valueChange{ _inifallOn(){    cheap.setOn(false, animated:true)}}

Target-Action and Delegate

UIButton

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

UISlider

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

UITextField

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

UITextView

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

UISearchBar

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

UIDatePicker

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

UIBarButtonItem

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

UIGestureRecognizer

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

Extensible

ExtendContainer and specifyHost to add more functionalities to your own types. For example

publicextensionContainerwhere Host:UITableView{func cellTap(_ action:@escaping(UITableViewCell)->Void)){    // Your code here here}}// usagelettableView=UITableView()tableView.on.cellTap{ cellin}

Installation

EasyClosure is available throughCocoaPods. To installit, simply add the following line to your Podfile:

pod'EasyClosure'

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

github"onmyway133/EasyClosure"

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

Author

Khoa Pham,onmyway133@gmail.com

Contributing

We would love you to contribute toEasyClosure, check theCONTRIBUTING file for more info.

License

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


[8]ページ先頭

©2009-2025 Movatter.jp