Latest0.0.3
Homepagehttps://github.com/zhxnlai/ReactiveUI
LicenseMIT
Platformsios 8.0, requires ARC
FrameworksUIKit
Authors

Reactive UI

A lightweight replacement for target action with closures, modified from Scream.swift.

Why?

In UIKit, Target-Action has been the default way to handle control events until the arrival of iOS 8 when UIAlertController introduces closure handler in UIAlertAction.

Closure handlers, in many cases, are more concise and readable than Target-Action. ReactiveUI follows this approach, wrapping existing Target-Action APIs

// UIControl
func addTarget(_ target: AnyObject?, action action: Selector, forControlEvents controlEvents: UIControlEvents)

// UIGestureRecognizer
init(target target: AnyObject, action action: Selector)

// ...

in closures

// UIControl
func addAction(action: UIControl -> (), forControlEvents events: UIControlEvents)

// UIGestureRecognizer
init(action: UIGestureRecognizer -> ())

// ...

With ReactiveUI, control events handling is much simpler:

var button = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 30))
button.setTitle("Title", forState: .Normal)
button.addAction({_ in println("TouchDown")}, forControlEvents: .TouchDown)
button.addAction({_ in println("TouchUpInside")}, forControlEvents: .TouchUpInside)
button.addAction({_ in println("TouchDragOutside")}, forControlEvents: .TouchDragOutside)

CocoaPods

You can install ReactiveUI through CocoaPods adding the following to your Podfile:

pod 'ReactiveUI'

CocoaPods’ support for swift is still pre-released, and requires your iOS deployment target to be 8.0 or later:

[sudo] gem install cocoapods --pre

Carthage

You can install ReactiveUI through Carthage adding the following to your Cartfile:

github 'zhxnlai/ReactiveUI'

Usage

Checkout the demo app for an example.

ReactiveUI

ReactiveUI currently supports the following classes:

UIControl

init(action: UIControl -> (), forControlEvents events: UIControlEvents)
init(forControlEvents events: UIControlEvents, action: UIControl -> ())
func addAction(action: UIControl -> (), forControlEvents events: UIControlEvents)
// can be called with a trailing closure
func forControlEvents(events: UIControlEvents, addAction action: UIControl -> ())
func removeAction(forControlEvents events: UIControlEvents)
func actionForControlEvent(events: UIControlEvents) -> (UIControl -> ())?
var actions: [UIControl -> ()]

UIBarButtonItem

init(barButtonSystemItem systemItem: UIBarButtonSystemItem, action: UIBarButtonItem -> ())
init(title: String?, style: UIBarButtonItemStyle, action: UIBarButtonItem -> ())
init(image: UIImage?, style: UIBarButtonItemStyle, action: UIBarButtonItem -> ())
init(image: UIImage?, landscapeImagePhone: UIImage?, style: UIBarButtonItemStyle, action: UIBarButtonItem -> ())
func addAction(action: UIBarButtonItem -> ())
func removeAction()

UIGestureRecognizer

init(action: UIGestureRecognizer -> ())
func addAction(action: UIGestureRecognizer -> ())
func removeAction()

NSTimer

class func scheduledTimerWithTimeInterval(seconds: NSTimeInterval, action: NSTimer -> (), repeats: Bool) -> NSTimer

License

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

Latest podspec

{
    "name": "ReactiveUI",
    "version": "0.0.3",
    "summary": "A lightweight replacement for target action with closures, modified from Scream.swift.",
    "homepage": "https://github.com/zhxnlai/ReactiveUI",
    "screenshots": "https://github.com/zhxnlai/ReactiveUI/raw/master/Previews/screenshot.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Zhixuan Lai": "[email protected]"
    },
    "social_media_url": "http://twitter.com/ZhixuanLai",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/zhxnlai/ReactiveUI.git",
        "tag": "0.0.3"
    },
    "source_files": "ReactiveUI/ReactiveUI/*.swift",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This