From 3f6bcf356e5df33bd42563aef1900a77b6bd3c3e Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sun, 13 Mar 2016 21:02:32 -0400 Subject: [PATCH 1/6] Added for the delegate method --- Rx.xcodeproj/project.pbxproj | 4 ++-- RxCocoa/iOS/UISearchBar+Rx.swift | 11 +++++++++++ Tests/RxCocoaTests/UISearchBar+RxTests.swift | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Rx.xcodeproj/project.pbxproj b/Rx.xcodeproj/project.pbxproj index d46fc555..439e06ed 100644 --- a/Rx.xcodeproj/project.pbxproj +++ b/Rx.xcodeproj/project.pbxproj @@ -1589,10 +1589,10 @@ C88254001B8A752B00B02D69 /* RxTableViewDataSourceProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTableViewDataSourceProxy.swift; sourceTree = ""; }; C88254011B8A752B00B02D69 /* RxTableViewDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTableViewDelegateProxy.swift; sourceTree = ""; }; C88254021B8A752B00B02D69 /* RxTextViewDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTextViewDelegateProxy.swift; sourceTree = ""; }; - C88254051B8A752B00B02D69 /* UIBarButtonItem+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIBarButtonItem+Rx.swift"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C88254051B8A752B00B02D69 /* UIBarButtonItem+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIBarButtonItem+Rx.swift"; sourceTree = ""; }; C88254061B8A752B00B02D69 /* UIButton+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Rx.swift"; sourceTree = ""; }; C88254071B8A752B00B02D69 /* UICollectionView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Rx.swift"; sourceTree = ""; }; - C88254081B8A752B00B02D69 /* UIControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIControl+Rx.swift"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C88254081B8A752B00B02D69 /* UIControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIControl+Rx.swift"; sourceTree = ""; }; C88254091B8A752B00B02D69 /* UIDatePicker+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDatePicker+Rx.swift"; sourceTree = ""; }; C882540A1B8A752B00B02D69 /* UIGestureRecognizer+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIGestureRecognizer+Rx.swift"; sourceTree = ""; }; C882540B1B8A752B00B02D69 /* UIImageView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+Rx.swift"; sourceTree = ""; }; diff --git a/RxCocoa/iOS/UISearchBar+Rx.swift b/RxCocoa/iOS/UISearchBar+Rx.swift index c93055f1..9a256274 100644 --- a/RxCocoa/iOS/UISearchBar+Rx.swift +++ b/RxCocoa/iOS/UISearchBar+Rx.swift @@ -68,6 +68,17 @@ extension UISearchBar { return ControlProperty(values: source, valueSink: bindingObserver) } + + /** + Reactive wrapper for delegate method `searchBarCancelButtonClicked`. + */ + public var rx_cancelTap: ControlEvent { + let source: Observable = rx_delegate.observe("searchBarCancelButtonClicked:") + .map { _ in + return () + } + return ControlEvent(events: source) + } } #endif diff --git a/Tests/RxCocoaTests/UISearchBar+RxTests.swift b/Tests/RxCocoaTests/UISearchBar+RxTests.swift index 8c962db5..1f2696eb 100644 --- a/Tests/RxCocoaTests/UISearchBar+RxTests.swift +++ b/Tests/RxCocoaTests/UISearchBar+RxTests.swift @@ -76,4 +76,23 @@ class UISearchBarTests : RxTest { _ = Observable.just(1).bindTo(searchBar.rx_selectedScopeButtonIndex) XCTAssertEqual(searchBar.selectedScopeButtonIndex, 1) } + + func testCancelTap() { + let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) + + var tapped = false + + let _ = searchBar.rx_cancelTap.subscribeNext { _ in + tapped = true + } + + XCTAssertFalse(tapped) + searchBar.delegate!.searchBarCancelButtonClicked!(searchBar) + XCTAssertTrue(tapped) + } + + func testCancelTap_DelegateEventCompletesOnDealloc() { + let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } + ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelTap } + } } \ No newline at end of file From 92911a68767cfc5f7e12145ad916d7e1f2007d1a Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sun, 13 Mar 2016 21:02:32 -0400 Subject: [PATCH 2/6] Added rx_cancelTap for the searchBarCancelButtonClicked: delegate method --- Rx.xcodeproj/project.pbxproj | 4 ++-- RxCocoa/iOS/UISearchBar+Rx.swift | 11 +++++++++++ Tests/RxCocoaTests/UISearchBar+RxTests.swift | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Rx.xcodeproj/project.pbxproj b/Rx.xcodeproj/project.pbxproj index d46fc555..439e06ed 100644 --- a/Rx.xcodeproj/project.pbxproj +++ b/Rx.xcodeproj/project.pbxproj @@ -1589,10 +1589,10 @@ C88254001B8A752B00B02D69 /* RxTableViewDataSourceProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTableViewDataSourceProxy.swift; sourceTree = ""; }; C88254011B8A752B00B02D69 /* RxTableViewDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTableViewDelegateProxy.swift; sourceTree = ""; }; C88254021B8A752B00B02D69 /* RxTextViewDelegateProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTextViewDelegateProxy.swift; sourceTree = ""; }; - C88254051B8A752B00B02D69 /* UIBarButtonItem+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIBarButtonItem+Rx.swift"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C88254051B8A752B00B02D69 /* UIBarButtonItem+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIBarButtonItem+Rx.swift"; sourceTree = ""; }; C88254061B8A752B00B02D69 /* UIButton+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Rx.swift"; sourceTree = ""; }; C88254071B8A752B00B02D69 /* UICollectionView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Rx.swift"; sourceTree = ""; }; - C88254081B8A752B00B02D69 /* UIControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIControl+Rx.swift"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C88254081B8A752B00B02D69 /* UIControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "UIControl+Rx.swift"; sourceTree = ""; }; C88254091B8A752B00B02D69 /* UIDatePicker+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDatePicker+Rx.swift"; sourceTree = ""; }; C882540A1B8A752B00B02D69 /* UIGestureRecognizer+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIGestureRecognizer+Rx.swift"; sourceTree = ""; }; C882540B1B8A752B00B02D69 /* UIImageView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+Rx.swift"; sourceTree = ""; }; diff --git a/RxCocoa/iOS/UISearchBar+Rx.swift b/RxCocoa/iOS/UISearchBar+Rx.swift index c93055f1..9a256274 100644 --- a/RxCocoa/iOS/UISearchBar+Rx.swift +++ b/RxCocoa/iOS/UISearchBar+Rx.swift @@ -68,6 +68,17 @@ extension UISearchBar { return ControlProperty(values: source, valueSink: bindingObserver) } + + /** + Reactive wrapper for delegate method `searchBarCancelButtonClicked`. + */ + public var rx_cancelTap: ControlEvent { + let source: Observable = rx_delegate.observe("searchBarCancelButtonClicked:") + .map { _ in + return () + } + return ControlEvent(events: source) + } } #endif diff --git a/Tests/RxCocoaTests/UISearchBar+RxTests.swift b/Tests/RxCocoaTests/UISearchBar+RxTests.swift index 8c962db5..1f2696eb 100644 --- a/Tests/RxCocoaTests/UISearchBar+RxTests.swift +++ b/Tests/RxCocoaTests/UISearchBar+RxTests.swift @@ -76,4 +76,23 @@ class UISearchBarTests : RxTest { _ = Observable.just(1).bindTo(searchBar.rx_selectedScopeButtonIndex) XCTAssertEqual(searchBar.selectedScopeButtonIndex, 1) } + + func testCancelTap() { + let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) + + var tapped = false + + let _ = searchBar.rx_cancelTap.subscribeNext { _ in + tapped = true + } + + XCTAssertFalse(tapped) + searchBar.delegate!.searchBarCancelButtonClicked!(searchBar) + XCTAssertTrue(tapped) + } + + func testCancelTap_DelegateEventCompletesOnDealloc() { + let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } + ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelTap } + } } \ No newline at end of file From dd37af0069f28aa7d35f69ead6f0857604c74bc4 Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sat, 26 Mar 2016 20:57:23 -0400 Subject: [PATCH 3/6] Additional UISearchBar Methods - Added the searchTap for the "searchBarSearchButtonClicked:" delegate method. - Added the "rx_createDelegateProxy" method to UISearchBar. --- .../Proxies/RxSearchBarDelegateProxy.swift | 17 ++++++-- RxCocoa/iOS/UISearchBar+Rx.swift | 20 +++++++++ .../DelegateProxyTest+UIKit.swift | 43 +++++++++++++++++++ Tests/RxCocoaTests/UISearchBar+RxTests.swift | 19 ++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) diff --git a/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift b/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift index 7f41b5df..26139a1f 100644 --- a/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift +++ b/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift @@ -14,19 +14,30 @@ import UIKit import RxSwift #endif -class RxSearchBarDelegateProxy : DelegateProxy +public class RxSearchBarDelegateProxy : DelegateProxy , UISearchBarDelegate , DelegateProxyType { - class func currentDelegateFor(object: AnyObject) -> AnyObject? { + public class func currentDelegateFor(object: AnyObject) -> AnyObject? { let searchBar: UISearchBar = castOrFatalError(object) return searchBar.delegate } - class func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) { + public class func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) { let searchBar: UISearchBar = castOrFatalError(object) searchBar.delegate = castOptionalOrFatalError(delegate) } + + // MARK: Delegate proxy methods + + /** + For more information take a look at `DelegateProxyType`. + */ + public override class func createProxyForObject(object: AnyObject) -> AnyObject { + let searchBar = (object as! UISearchBar) + + return castOrFatalError(searchBar.rx_createDelegateProxy()) + } } #endif diff --git a/RxCocoa/iOS/UISearchBar+Rx.swift b/RxCocoa/iOS/UISearchBar+Rx.swift index e2f8dc46..3f31a8c1 100644 --- a/RxCocoa/iOS/UISearchBar+Rx.swift +++ b/RxCocoa/iOS/UISearchBar+Rx.swift @@ -18,6 +18,15 @@ import UIKit extension UISearchBar { + /** + Factory method that enables subclasses to implement their own `rx_delegate`. + + - returns: Instance of delegate proxy that wraps `delegate`. + */ + public func rx_createDelegateProxy() -> RxSearchBarDelegateProxy { + return RxSearchBarDelegateProxy(parentObject: self) + } + /** Reactive wrapper for `delegate`. @@ -79,6 +88,17 @@ extension UISearchBar { } return ControlEvent(events: source) } + + /** + Reactive wrapper for delegate method `searchBarSearchButtonClicked`. + */ + public var rx_searchTap: ControlEvent { + let source: Observable = rx_delegate.observe("searchBarSearchButtonClicked:") + .map { _ in + return () + } + return ControlEvent(events: source) + } } #endif diff --git a/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift b/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift index c2669f70..e22a7bc1 100644 --- a/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift +++ b/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift @@ -44,6 +44,12 @@ import XCTest optional func testEventHappened(value: Int) } +@objc protocol UISearchBarDelegateSubclass + : UISearchBarDelegate + , TestDelegateProtocol { + optional func testEventHappened(value: Int) +} + @objc protocol UITextViewDelegateSubclass : UITextViewDelegate , TestDelegateProtocol { @@ -88,6 +94,14 @@ extension DelegateProxyTest { } } +// MARK: UISearchBar + +extension DelegateProxyTest { + func test_UISearchBarDelegateExtension() { + performDelegateTest(UISearchBarSubclass(frame: CGRect.zero)) + } +} + // MARK: UITextView extension DelegateProxyTest { @@ -243,6 +257,35 @@ class UIScrollViewSubclass } } +class ExtendSearchBarDelegateProxy + : RxSearchBarDelegateProxy + , UISearchBarDelegateSubclass { + weak private(set) var control: UISearchBarSubclass? + + required init(parentObject: AnyObject) { + self.control = (parentObject as! UISearchBarSubclass) + super.init(parentObject: parentObject) + } +} + +class UISearchBarSubclass + : UISearchBar + , TestDelegateControl { + override func rx_createDelegateProxy() -> RxSearchBarDelegateProxy { + return ExtendSearchBarDelegateProxy(parentObject: self) + } + + func doThatTest(value: Int) { + (delegate as! TestDelegateProtocol).testEventHappened?(value) + } + + var test: Observable { + return rx_delegate + .observe(#selector(TestDelegateProtocol.testEventHappened(_:))) + .map { a in (a[0] as! NSNumber).integerValue } + } +} + class ExtendTextViewDelegateProxy : RxTextViewDelegateProxy , UITextViewDelegateSubclass { diff --git a/Tests/RxCocoaTests/UISearchBar+RxTests.swift b/Tests/RxCocoaTests/UISearchBar+RxTests.swift index 1f2696eb..2a74e5fd 100644 --- a/Tests/RxCocoaTests/UISearchBar+RxTests.swift +++ b/Tests/RxCocoaTests/UISearchBar+RxTests.swift @@ -95,4 +95,23 @@ class UISearchBarTests : RxTest { let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelTap } } + + func testSearchTap() { + let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) + + var tapped = false + + let _ = searchBar.rx_searchTap.subscribeNext { _ in + tapped = true + } + + XCTAssertFalse(tapped) + searchBar.delegate!.searchBarSearchButtonClicked!(searchBar) + XCTAssertTrue(tapped) + } + + func testSearchTap_DelegateEventCompletesOnDealloc() { + let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } + ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_searchTap } + } } \ No newline at end of file From 2db92e9727b611aa2ee122e6e29d0fc6c7ceeb23 Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sat, 26 Mar 2016 21:02:09 -0400 Subject: [PATCH 4/6] Upgraded UISearchBar selectors to Swift 2.2 selectors --- RxCocoa/iOS/UISearchBar+Rx.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RxCocoa/iOS/UISearchBar+Rx.swift b/RxCocoa/iOS/UISearchBar+Rx.swift index 3f31a8c1..520b413c 100644 --- a/RxCocoa/iOS/UISearchBar+Rx.swift +++ b/RxCocoa/iOS/UISearchBar+Rx.swift @@ -82,7 +82,7 @@ extension UISearchBar { Reactive wrapper for delegate method `searchBarCancelButtonClicked`. */ public var rx_cancelTap: ControlEvent { - let source: Observable = rx_delegate.observe("searchBarCancelButtonClicked:") + let source: Observable = rx_delegate.observe(#selector(UISearchBarDelegate.searchBarCancelButtonClicked(_:))) .map { _ in return () } @@ -93,7 +93,7 @@ extension UISearchBar { Reactive wrapper for delegate method `searchBarSearchButtonClicked`. */ public var rx_searchTap: ControlEvent { - let source: Observable = rx_delegate.observe("searchBarSearchButtonClicked:") + let source: Observable = rx_delegate.observe(#selector(UISearchBarDelegate.searchBarSearchButtonClicked(_:))) .map { _ in return () } From f58d032d344d430052af41e7f4e0bc610d8a6ce9 Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sun, 27 Mar 2016 21:31:53 -0400 Subject: [PATCH 5/6] tvOS Fixes for UISearchBar - `searchBarCancelButtonClicked:` is only available on iOS. - UISearchBar instantiation is not supported on tvOS, so all subclass delegate methods and tests are skipped. --- RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift | 3 +++ RxCocoa/iOS/UISearchBar+Rx.swift | 4 ++++ Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift | 7 +++++++ Tests/RxCocoaTests/UISearchBar+RxTests.swift | 2 ++ 4 files changed, 16 insertions(+) diff --git a/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift b/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift index 26139a1f..14b84cec 100644 --- a/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift +++ b/RxCocoa/iOS/Proxies/RxSearchBarDelegateProxy.swift @@ -30,6 +30,7 @@ public class RxSearchBarDelegateProxy : DelegateProxy // MARK: Delegate proxy methods +#if os(iOS) /** For more information take a look at `DelegateProxyType`. */ @@ -38,6 +39,8 @@ public class RxSearchBarDelegateProxy : DelegateProxy return castOrFatalError(searchBar.rx_createDelegateProxy()) } +#endif + } #endif diff --git a/RxCocoa/iOS/UISearchBar+Rx.swift b/RxCocoa/iOS/UISearchBar+Rx.swift index 520b413c..a1a4c427 100644 --- a/RxCocoa/iOS/UISearchBar+Rx.swift +++ b/RxCocoa/iOS/UISearchBar+Rx.swift @@ -18,6 +18,7 @@ import UIKit extension UISearchBar { +#if os(iOS) /** Factory method that enables subclasses to implement their own `rx_delegate`. @@ -26,6 +27,7 @@ extension UISearchBar { public func rx_createDelegateProxy() -> RxSearchBarDelegateProxy { return RxSearchBarDelegateProxy(parentObject: self) } +#endif /** Reactive wrapper for `delegate`. @@ -78,6 +80,7 @@ extension UISearchBar { return ControlProperty(values: source, valueSink: bindingObserver) } +#if os(iOS) /** Reactive wrapper for delegate method `searchBarCancelButtonClicked`. */ @@ -88,6 +91,7 @@ extension UISearchBar { } return ControlEvent(events: source) } +#endif /** Reactive wrapper for delegate method `searchBarSearchButtonClicked`. diff --git a/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift b/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift index e22a7bc1..64bd2114 100644 --- a/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift +++ b/Tests/RxCocoaTests/DelegateProxyTest+UIKit.swift @@ -44,11 +44,13 @@ import XCTest optional func testEventHappened(value: Int) } +#if os(iOS) @objc protocol UISearchBarDelegateSubclass : UISearchBarDelegate , TestDelegateProtocol { optional func testEventHappened(value: Int) } +#endif @objc protocol UITextViewDelegateSubclass : UITextViewDelegate @@ -96,11 +98,13 @@ extension DelegateProxyTest { // MARK: UISearchBar +#if os(iOS) extension DelegateProxyTest { func test_UISearchBarDelegateExtension() { performDelegateTest(UISearchBarSubclass(frame: CGRect.zero)) } } +#endif // MARK: UITextView @@ -257,6 +261,7 @@ class UIScrollViewSubclass } } +#if os(iOS) class ExtendSearchBarDelegateProxy : RxSearchBarDelegateProxy , UISearchBarDelegateSubclass { @@ -271,6 +276,7 @@ class ExtendSearchBarDelegateProxy class UISearchBarSubclass : UISearchBar , TestDelegateControl { + override func rx_createDelegateProxy() -> RxSearchBarDelegateProxy { return ExtendSearchBarDelegateProxy(parentObject: self) } @@ -285,6 +291,7 @@ class UISearchBarSubclass .map { a in (a[0] as! NSNumber).integerValue } } } +#endif class ExtendTextViewDelegateProxy : RxTextViewDelegateProxy diff --git a/Tests/RxCocoaTests/UISearchBar+RxTests.swift b/Tests/RxCocoaTests/UISearchBar+RxTests.swift index 2a74e5fd..8676b53e 100644 --- a/Tests/RxCocoaTests/UISearchBar+RxTests.swift +++ b/Tests/RxCocoaTests/UISearchBar+RxTests.swift @@ -77,6 +77,7 @@ class UISearchBarTests : RxTest { XCTAssertEqual(searchBar.selectedScopeButtonIndex, 1) } +#if os(iOS) func testCancelTap() { let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) @@ -95,6 +96,7 @@ class UISearchBarTests : RxTest { let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelTap } } +#endif func testSearchTap() { let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) From d6731613d923b45e5655b8119ef9ebd45e51606e Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sat, 9 Apr 2016 18:22:29 -0400 Subject: [PATCH 6/6] Switched to ButtonClicked over Tap for UISearchBar delegate methods --- RxCocoa/iOS/UISearchBar+Rx.swift | 4 ++-- Tests/RxCocoaTests/UISearchBar+RxTests.swift | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/RxCocoa/iOS/UISearchBar+Rx.swift b/RxCocoa/iOS/UISearchBar+Rx.swift index a1a4c427..73413dc0 100644 --- a/RxCocoa/iOS/UISearchBar+Rx.swift +++ b/RxCocoa/iOS/UISearchBar+Rx.swift @@ -84,7 +84,7 @@ extension UISearchBar { /** Reactive wrapper for delegate method `searchBarCancelButtonClicked`. */ - public var rx_cancelTap: ControlEvent { + public var rx_cancelButtonClicked: ControlEvent { let source: Observable = rx_delegate.observe(#selector(UISearchBarDelegate.searchBarCancelButtonClicked(_:))) .map { _ in return () @@ -96,7 +96,7 @@ extension UISearchBar { /** Reactive wrapper for delegate method `searchBarSearchButtonClicked`. */ - public var rx_searchTap: ControlEvent { + public var rx_searchButtonClicked: ControlEvent { let source: Observable = rx_delegate.observe(#selector(UISearchBarDelegate.searchBarSearchButtonClicked(_:))) .map { _ in return () diff --git a/Tests/RxCocoaTests/UISearchBar+RxTests.swift b/Tests/RxCocoaTests/UISearchBar+RxTests.swift index 8676b53e..4c9b91f5 100644 --- a/Tests/RxCocoaTests/UISearchBar+RxTests.swift +++ b/Tests/RxCocoaTests/UISearchBar+RxTests.swift @@ -78,12 +78,12 @@ class UISearchBarTests : RxTest { } #if os(iOS) - func testCancelTap() { + func testCancelButtonClicked() { let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) var tapped = false - let _ = searchBar.rx_cancelTap.subscribeNext { _ in + let _ = searchBar.rx_cancelButtonClicked.subscribeNext { _ in tapped = true } @@ -92,18 +92,18 @@ class UISearchBarTests : RxTest { XCTAssertTrue(tapped) } - func testCancelTap_DelegateEventCompletesOnDealloc() { + func testCancelButtonClicked_DelegateEventCompletesOnDealloc() { let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } - ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelTap } + ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelButtonClicked } } #endif - func testSearchTap() { + func testSearchButtonClicked() { let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1)) var tapped = false - let _ = searchBar.rx_searchTap.subscribeNext { _ in + let _ = searchBar.rx_searchButtonClicked.subscribeNext { _ in tapped = true } @@ -112,8 +112,8 @@ class UISearchBarTests : RxTest { XCTAssertTrue(tapped) } - func testSearchTap_DelegateEventCompletesOnDealloc() { + func testSearchButtonClicked_DelegateEventCompletesOnDealloc() { let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) } - ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_searchTap } + ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_searchButtonClicked } } } \ No newline at end of file