Skip to content

Closure driven event handling in CocoaTouch framework

License

Notifications You must be signed in to change notification settings

mislavjavor/LambdaUI

Repository files navigation

LambdaUI

Logo

Version Build Status Coverage Status

Requirements

Minimum iOS 8.0

Example

To run the example project, clone the repo, and open LambdaUI.xcworkspace

Installation

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

pod "LambdaUI"

What is LambdaUI?

LambdaUI is an closure driven event handling framework for Swift. It reduces the effort needed when assigning events to UI elements in Swift. It also features easy and intuitive GCD support.

Setup

Once you've added the LambdaUI framework to your project, a new events property will be available on all instances of UIControl objects (for example, UIButton, UIStepper, UISlider, etc.). This property contains all of the supported events for a given UIControl

Using LambdaUI

Add events to UIControl instances

let button = UIButton()
button.events.touchUpInside += { _ in
  print("Touched the button")
}

Remove added events easily

let stepper = UIStepper()
let eventIdentidier = stepper.events.valueChanged += { _ in
  print("Stepper changed value")
}

if shouldDisableStepperEvents {
  stepper.events.valueChanged -= eventIdentidier
}

Easily add async events

let slider = UISlider()
slider.events.valueChanged += async {
  print("async event")
}

slider.events.valueChanged += async(queue: .UserInteractiveQueue) { _ in
  print("async event on user interactive queue")
}

Mix and match/add multiple events

@IBOutlet weak var button : UIButton!

override func viewDidLoad() {
  super.viewDidLoad()
  let firstEventIdentifier = button.events.touchUpInside += { _ in
    print("Do first event")
  }

  button.events.touchUpInside += async(queue: .BackgroundQueue) { _ in
    //Disable first event once the second event has been triggered
    button.events.touchUpInside -= firstEventIdentifier
  }
}

Contributing

Any contributions are welcome. Just respect the usual contribution etiquette. Submit a pull request and it will be reviewed as soon as possible.

Author

Mislav Javor, [email protected]

License

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

About

Closure driven event handling in CocoaTouch framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published