From 300c44aced2e0fcbd4ad3fda0a3605c64b8648b7 Mon Sep 17 00:00:00 2001 From: Krunoslav Zaher Date: Sat, 13 Feb 2016 23:36:01 +0100 Subject: [PATCH] More workarounds for Swift compiler bugs. --- RxCocoa/OSX/NSControl+Rx.swift | 15 +++++++++++---- RxCocoa/iOS/UIControl+Rx.swift | 2 +- scripts/common.sh | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/RxCocoa/OSX/NSControl+Rx.swift b/RxCocoa/OSX/NSControl+Rx.swift index d9dc98e0..a2f6065d 100644 --- a/RxCocoa/OSX/NSControl+Rx.swift +++ b/RxCocoa/OSX/NSControl+Rx.swift @@ -43,10 +43,17 @@ extension NSControl { return ControlEvent(events: source) } - static func rx_value(control: C, getter: (C) -> T, setter: (C, T) -> Void) -> ControlProperty { + /** + You might be wondering why the ugly `as!` casts etc, well, for some reason if + Swift compiler knows C is UIControl type and optimizations are turned on, it will crash. + + Can somebody offer poor Swift compiler writers some other better job maybe, this is becoming + ridiculous. So much time wasted ... + */ + static func rx_value(control: C, getter: (C) -> T, setter: (C, T) -> Void) -> ControlProperty { MainScheduler.ensureExecutingOnScheduler() - let source = control.rx_lazyInstanceObservable(&rx_value_key) { () -> Observable in + let source = (control as! NSObject).rx_lazyInstanceObservable(&rx_value_key) { () -> Observable in return Observable.create { [weak weakControl = control] (observer: AnyObserver) in guard let control = weakControl else { observer.on(.Completed) @@ -55,7 +62,7 @@ extension NSControl { observer.on(.Next(getter(control))) - let observer = ControlTarget(control: control) { _ in + let observer = ControlTarget(control: control as! NSControl) { _ in if let control = weakControl { observer.on(.Next(getter(control))) } @@ -64,7 +71,7 @@ extension NSControl { return observer } .distinctUntilChanged() - .takeUntil(control.rx_deallocated) + .takeUntil((control as! NSObject).rx_deallocated) } let bindingObserver = UIBindingObserver(UIElement: control, binding: setter) diff --git a/RxCocoa/iOS/UIControl+Rx.swift b/RxCocoa/iOS/UIControl+Rx.swift index ce1e5acf..5ecccfc6 100644 --- a/RxCocoa/iOS/UIControl+Rx.swift +++ b/RxCocoa/iOS/UIControl+Rx.swift @@ -57,7 +57,7 @@ extension UIControl { Swift compiler knows C is UIControl type and optimizations are turned on, it will crash. Can somebody offer poor Swift compiler writers some other better job maybe, this is becoming - rediculous. + ridiculous. So much time wasted ... */ static func rx_value(control: C, getter: (C) -> T, setter: (C, T) -> Void) -> ControlProperty { let source: Observable = Observable.create { [weak weakControl = control] observer in diff --git a/scripts/common.sh b/scripts/common.sh index a9d69c4c..3c459da2 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,6 +1,5 @@ #!/bin/bash set -e -#set -o xtrace RESET="\033[0m" BLACK="\033[30m" @@ -134,12 +133,14 @@ function action() { fi STATUS="" + set -x xcodebuild -workspace "${WORKSPACE}" \ -scheme "${SCHEME}" \ -configuration "${CONFIGURATION}" \ -derivedDataPath "${BUILD_DIRECTORY}" \ -destination "$DESTINATION" \ $ACTION | xcpretty -c; STATUS=${PIPESTATUS[0]} + set +x if [ $STATUS -ne 0 ]; then echo $STATUS