From 8803d0f03db8256501c40289a04aaaca2f3ba44e Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Sun, 2 Dec 2018 09:56:44 -0200 Subject: [PATCH 1/2] Syntax sugar to execute when Input is Void. --- Sources/Action/Action.swift | 7 +++++++ Sources/Action/UIKitExtensions/UIAlertAction+Action.swift | 2 +- .../Action/UIKitExtensions/UIBarButtonItem+Action.swift | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Action/Action.swift b/Sources/Action/Action.swift index 8ed51961..08cf5101 100644 --- a/Sources/Action/Action.swift +++ b/Sources/Action/Action.swift @@ -135,3 +135,10 @@ public final class Action { return subject.asObservable() } } + +extension Action where Input == Void { + @discardableResult + public func execute() -> Observable { + return execute(()) + } +} diff --git a/Sources/Action/UIKitExtensions/UIAlertAction+Action.swift b/Sources/Action/UIKitExtensions/UIAlertAction+Action.swift index 5b4cea0e..6ccde03f 100644 --- a/Sources/Action/UIKitExtensions/UIAlertAction+Action.swift +++ b/Sources/Action/UIKitExtensions/UIAlertAction+Action.swift @@ -13,7 +13,7 @@ public extension UIAlertAction { public static func Action(_ title: String?, style: ActionStyle) -> UIAlertAction { return UIAlertAction(title: title, style: style, handler: { action in - action.rx.action?.execute(()) + action.rx.action?.execute() return }) } diff --git a/Sources/Action/UIKitExtensions/UIBarButtonItem+Action.swift b/Sources/Action/UIKitExtensions/UIBarButtonItem+Action.swift index 63977f1e..500818c8 100644 --- a/Sources/Action/UIKitExtensions/UIBarButtonItem+Action.swift +++ b/Sources/Action/UIKitExtensions/UIBarButtonItem+Action.swift @@ -31,7 +31,7 @@ public extension Reactive where Base: UIBarButtonItem { .disposed(by: self.base.actionDisposeBag) self.tap.subscribe(onNext: { - action.execute(()) + action.execute() }) .disposed(by: self.base.actionDisposeBag) } From e1eb74575cdacb558f51121111ed2aac68e27542 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Sun, 2 Dec 2018 18:20:03 -0200 Subject: [PATCH 2/2] Changelog entry. --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 98d1ca1b..7f133f11 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,7 +5,7 @@ Changelog Current master -------------- -- Nothing yet! +- Adding syntax sugar `execute()` method on `Action` when `Input` is `Void`. [#171](https://github.com/RxSwiftCommunity/Action/pull/171) 3.9.1 -----