From f58d032d344d430052af41e7f4e0bc610d8a6ce9 Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Sun, 27 Mar 2016 21:31:53 -0400 Subject: [PATCH] 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))