Fixes build for all schemes.
This commit is contained in:
parent
53bd68f5ba
commit
fa5d9ec97e
|
|
@ -639,7 +639,7 @@
|
|||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "ENABLE_SWIZZLING=1";
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "";
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
|
|
@ -649,7 +649,6 @@
|
|||
INFOPLIST_FILE = RxCocoa/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
OTHER_SWIFT_FLAGS = "-D ENABLE_SWIZZLING";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = "";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ public class DelegateProxy : _RXDelegateProxy {
|
|||
}
|
||||
|
||||
deinit {
|
||||
for v in subjectsForSelector.values {
|
||||
sendCompleted(v)
|
||||
}
|
||||
#if TRACE_RESOURCES
|
||||
OSAtomicDecrement32(&resourceCount)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -149,23 +149,6 @@ func installDelegate<P: DelegateProxyType>(proxy: P, delegate: AnyObject, retain
|
|||
}
|
||||
}
|
||||
|
||||
func proxyObservableForObject<P: DelegateProxyType, Element, DisposeKey>(object: AnyObject,
|
||||
addObserver: (P, ObserverOf<Element>) -> DisposeKey,
|
||||
removeObserver: (P, DisposeKey) -> ())
|
||||
-> Observable<Element> {
|
||||
|
||||
return AnonymousObservable { observer in
|
||||
let proxy: P = proxyForObject(object)
|
||||
let key = addObserver(proxy, observer)
|
||||
|
||||
return AnonymousDisposable {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
removeObserver(proxy, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setProxyDataSourceForObject<P: DelegateProxyType, Element>(object: AnyObject, dataSource: AnyObject, retainDataSource: Bool, binding: (P, Event<Element>) -> Void)
|
||||
-> Observable<Element> -> Disposable {
|
||||
return { source in
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
#if ENABLE_SWIZZLING
|
||||
class Deallocating : NSObject
|
||||
, RXDeallocating {
|
||||
typealias DeallocatingAction = () -> ()
|
||||
|
|
@ -21,4 +22,5 @@ class Deallocating : NSObject
|
|||
func deallocating() {
|
||||
deallocatingAction()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
import Foundation
|
||||
import RxSwift
|
||||
|
||||
|
||||
class KVOObservable<Element> : Producer<Element?>
|
||||
, KVOObservableProtocol {
|
||||
unowned var target: AnyObject
|
||||
|
|
@ -45,6 +44,8 @@ class KVOObservable<Element> : Producer<Element?>
|
|||
|
||||
}
|
||||
|
||||
#if ENABLE_SWIZZLING
|
||||
|
||||
func observeWeaklyKeyPathFor(target: NSObject, # keyPath: String, # options: NSKeyValueObservingOptions) -> Observable<AnyObject?> {
|
||||
let components = keyPath.componentsSeparatedByString(".").filter { $0 != "self" }
|
||||
|
||||
|
|
@ -137,4 +138,5 @@ func observeWeaklyKeyPathFor(
|
|||
}
|
||||
}
|
||||
>- switchLatest
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -54,8 +54,11 @@ extension NSObject {
|
|||
public func rx_observe<Element>(keyPath: String, options: NSKeyValueObservingOptions, retainSelf: Bool) -> Observable<Element?> {
|
||||
return KVOObservable(object: self, keyPath: keyPath, options: options, retainTarget: retainSelf)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if ENABLE_SWIZZLING
|
||||
// KVO
|
||||
extension NSObject {
|
||||
// Observes values on `keyPath` starting from `self` with `.Initial | .New` options.
|
||||
// Doesn't retain `self` and when `self` is deallocated, completes the sequence.
|
||||
public func rx_observeWeakly<Element>(keyPath: String) -> Observable<Element?> {
|
||||
|
|
@ -70,8 +73,8 @@ extension NSObject {
|
|||
return n as? Element
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Dealloc
|
||||
extension NSObject {
|
||||
|
|
|
|||
|
|
@ -13,22 +13,19 @@ import RxSwift
|
|||
class RxTextFieldDelegate : DelegateProxy
|
||||
, NSTextFieldDelegate
|
||||
, DelegateProxyType {
|
||||
typealias Observer = ObserverOf<String>
|
||||
typealias DisposeKey = Bag<Observer>.KeyType
|
||||
|
||||
var observers: Bag<Observer> = Bag()
|
||||
|
||||
let textField: NSTextField
|
||||
let textSubject = ReplaySubject<String>(bufferSize: 1)
|
||||
|
||||
required init(parentObject: AnyObject) {
|
||||
self.textField = parentObject as! NSTextField
|
||||
super.init(parentObject: parentObject)
|
||||
sendNext(self.textSubject, self.textField.stringValue)
|
||||
}
|
||||
|
||||
override func controlTextDidChange(notification: NSNotification) {
|
||||
let textField = notification.object as! NSTextField
|
||||
let nextValue = textField.stringValue
|
||||
dispatchNext(nextValue, observers)
|
||||
sendNext(self.textSubject, nextValue)
|
||||
}
|
||||
|
||||
class func currentDelegateFor(object: AnyObject) -> AnyObject? {
|
||||
|
|
@ -67,11 +64,8 @@ extension NSTextField {
|
|||
}
|
||||
|
||||
public var rx_text: Observable<String> {
|
||||
return proxyObservableForObject(self, { (p: RxTextFieldDelegate, o) in
|
||||
sendNext(o, self.stringValue)
|
||||
return p.observers.put(o)
|
||||
}, { p, d in
|
||||
p.observers.removeKey(d)
|
||||
})
|
||||
let delegate = proxyForObject(self) as RxTextFieldDelegate
|
||||
|
||||
return delegate.textSubject
|
||||
}
|
||||
}
|
||||
|
|
@ -14,41 +14,30 @@ import UIKit
|
|||
class RxScrollViewDelegateProxy : DelegateProxy
|
||||
, UIScrollViewDelegate
|
||||
, DelegateProxyType {
|
||||
typealias ContentOffsetObserver = ObserverOf<CGPoint>
|
||||
typealias ContentOffsetDisposeKey = Bag<ContentOffsetObserver>.KeyType
|
||||
private var _contentOffsetSubject: ReplaySubject<CGPoint>?
|
||||
|
||||
var contentOffsetObservers: Bag<ContentOffsetObserver>?
|
||||
|
||||
unowned let scrollView: UIScrollView
|
||||
|
||||
var contentOffsetSubject: Observable<CGPoint> {
|
||||
if _contentOffsetSubject == nil {
|
||||
_contentOffsetSubject = ReplaySubject(bufferSize: 1)
|
||||
sendNext(_contentOffsetSubject!, self.scrollView.contentOffset)
|
||||
}
|
||||
|
||||
return _contentOffsetSubject!
|
||||
}
|
||||
|
||||
required init(parentObject: AnyObject) {
|
||||
self.scrollView = parentObject as! UIScrollView
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
||||
// registering / unregistering observers
|
||||
|
||||
func addContentOffsetObserver(observer: ContentOffsetObserver) -> ContentOffsetDisposeKey {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
if contentOffsetObservers == nil {
|
||||
contentOffsetObservers = Bag()
|
||||
}
|
||||
return contentOffsetObservers!.put(observer)
|
||||
}
|
||||
|
||||
func removeContentOffsetObserver(key: ContentOffsetDisposeKey) {
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
let element = contentOffsetObservers?.removeKey(key)
|
||||
if element == nil {
|
||||
removingObserverFailed()
|
||||
}
|
||||
}
|
||||
|
||||
// delegate methods
|
||||
|
||||
func scrollViewDidScroll(scrollView: UIScrollView) {
|
||||
dispatchNext(scrollView.contentOffset, contentOffsetObservers)
|
||||
if let contentOffset = _contentOffsetSubject {
|
||||
sendNext(contentOffset, self.scrollView.contentOffset)
|
||||
}
|
||||
self._forwardToDelegate?.scrollViewDidScroll?(scrollView)
|
||||
}
|
||||
|
||||
|
|
@ -69,4 +58,10 @@ class RxScrollViewDelegateProxy : DelegateProxy
|
|||
let collectionView: UIScrollView = castOrFatalError(object)
|
||||
return collectionView.delegate
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let contentOffset = _contentOffsetSubject {
|
||||
sendCompleted(contentOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,20 +20,20 @@ extension UIActionSheet {
|
|||
return rx_delegate.observe("actionSheet:clickedButtonAtIndex:")
|
||||
>- map { a in
|
||||
return a[1] as! Int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var rx_willDismissWithButtonIndex: Observable<Int> {
|
||||
return rx_delegate.observe("actionSheet:willDismissWithButtonIndex:")
|
||||
>- map { a in
|
||||
return a[1] as! Int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var rx_didDismissWithButtonIndex: Observable<Int> {
|
||||
return rx_delegate.observe("actionSheet:didDismissWithButtonIndex:")
|
||||
>- map { a in
|
||||
return a[1] as! Int
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,20 +20,20 @@ extension UIAlertView {
|
|||
return rx_delegate.observe("alertView:clickedButtonAtIndex:")
|
||||
>- map { a in
|
||||
return a[1] as! Int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var rx_willDismissWithButtonIndex: Observable<Int> {
|
||||
return rx_delegate.observe("alertView:willDismissWithButtonIndex:")
|
||||
>- map { a in
|
||||
return a[1] as! Int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var rx_didDismissWithButtonIndex: Observable<Int> {
|
||||
return rx_delegate.observe("alertView:didDismissWithButtonIndex:")
|
||||
>- map { a in
|
||||
return a[1] as! Int
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ extension UIBarButtonItem {
|
|||
sendNext(observer, ())
|
||||
}
|
||||
return target
|
||||
}
|
||||
} >- takeUntil(rx_deallocated)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ extension UIControl {
|
|||
return AnonymousDisposable {
|
||||
controlTarget.dispose()
|
||||
}
|
||||
}
|
||||
} >- takeUntil(rx_deallocated)
|
||||
}
|
||||
|
||||
func rx_value<T>(getValue: () -> T) -> Observable<T> {
|
||||
|
|
@ -38,7 +38,7 @@ extension UIControl {
|
|||
return AnonymousDisposable {
|
||||
controlTarget.dispose()
|
||||
}
|
||||
}
|
||||
} >- takeUntil(rx_deallocated)
|
||||
}
|
||||
|
||||
public func rx_subscribeEnabledTo(source: Observable<Bool>) -> Disposable {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ extension UIGestureRecognizer {
|
|||
}
|
||||
|
||||
return observer
|
||||
}
|
||||
} >- takeUntil(rx_deallocated)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,35 +12,37 @@ import UIKit
|
|||
|
||||
extension UIImageView {
|
||||
public func rx_subscribeImageTo(source: Observable<UIImage?>) -> Disposable {
|
||||
return rx_subscribeImageTo(false)(source: source)
|
||||
return rx_subscribeImageTo(false)(source)
|
||||
}
|
||||
|
||||
public func rx_subscribeImageTo
|
||||
(animated: Bool)
|
||||
(source: Observable<UIImage?>) -> Disposable {
|
||||
return source.subscribe(AnonymousObserver { event in
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
switch event {
|
||||
case .Next(let boxedValue):
|
||||
let value = boxedValue.value
|
||||
if animated && value != nil {
|
||||
let transition = CATransition()
|
||||
transition.duration = 0.25
|
||||
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
transition.type = kCATransitionFade
|
||||
self.layer.addAnimation(transition, forKey: kCATransition)
|
||||
-> Observable<UIImage?> -> Disposable {
|
||||
return { source in
|
||||
return source.subscribe(AnonymousObserver { event in
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
switch event {
|
||||
case .Next(let boxedValue):
|
||||
let value = boxedValue.value
|
||||
if animated && value != nil {
|
||||
let transition = CATransition()
|
||||
transition.duration = 0.25
|
||||
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
transition.type = kCATransitionFade
|
||||
self.layer.addAnimation(transition, forKey: kCATransition)
|
||||
}
|
||||
else {
|
||||
self.layer.removeAllAnimations()
|
||||
}
|
||||
self.image = value
|
||||
case .Error(let error):
|
||||
bindingErrorToInterface(error)
|
||||
break
|
||||
case .Completed:
|
||||
break
|
||||
}
|
||||
else {
|
||||
self.layer.removeAllAnimations()
|
||||
}
|
||||
self.image = value
|
||||
case .Error(let error):
|
||||
bindingErrorToInterface(error)
|
||||
break
|
||||
case .Completed:
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,11 +27,9 @@ extension UIScrollView {
|
|||
// properties
|
||||
|
||||
public var rx_contentOffset: Observable<CGPoint> {
|
||||
return proxyObservableForObject(self, { (b: RxScrollViewDelegateProxy, o) in
|
||||
return b.addContentOffsetObserver(o)
|
||||
}, { (b, d) -> () in
|
||||
b.removeContentOffsetObserver(d)
|
||||
})
|
||||
let proxy = proxyForObject(self) as RxScrollViewDelegateProxy
|
||||
|
||||
return proxy.contentOffsetSubject
|
||||
}
|
||||
|
||||
// delegate
|
||||
|
|
|
|||
|
|
@ -253,6 +253,7 @@ extension KVOObservableTests {
|
|||
}
|
||||
}
|
||||
|
||||
#if ENABLE_SWIZZLING
|
||||
// test weak observe
|
||||
|
||||
extension KVOObservableTests {
|
||||
|
|
@ -788,4 +789,5 @@ extension KVOObservableTests {
|
|||
|
||||
XCTAssertTrue(rootDeallocated)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ extension NSObjectTests {
|
|||
}
|
||||
}
|
||||
|
||||
#if ENABLE_SWIZZLING
|
||||
// rx_deallocating
|
||||
extension NSObjectTests {
|
||||
func testDeallocating_ObservableFires() {
|
||||
|
|
@ -141,4 +142,5 @@ extension NSObjectTests {
|
|||
|
||||
XCTAssertFalse(fired)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -223,4 +223,31 @@ class DelegateProxyTest : RxTest {
|
|||
|
||||
XCTAssertEqual(mock.messages, [])
|
||||
}
|
||||
|
||||
func test_delegateProxyCompletesOnDealloc() {
|
||||
var view: ThreeDSectionedView! = ThreeDSectionedView()
|
||||
let mock = MockThreeDSectionedViewProtocol()
|
||||
|
||||
view.delegate = mock
|
||||
|
||||
let completed = RxMutableBox(false)
|
||||
|
||||
autoreleasepool {
|
||||
XCTAssertTrue(!mock.respondsToSelector("threeDView(threeDView:didGetXXX:"))
|
||||
|
||||
let sentArgument = NSIndexPath(index: 0)
|
||||
|
||||
var receivedArgument: NSIndexPath? = nil
|
||||
|
||||
view.rx_proxy.observe("threeDView:didGetXXX:")
|
||||
>- subscribeCompleted {
|
||||
completed.value = true
|
||||
}
|
||||
|
||||
view.delegate?.threeDView?(view, didGetXXX: sentArgument)
|
||||
}
|
||||
XCTAssertTrue(!completed.value)
|
||||
view = nil
|
||||
XCTAssertTrue(completed.value)
|
||||
}
|
||||
}
|
||||
|
|
@ -490,7 +490,7 @@
|
|||
"-framework",
|
||||
XCTest,
|
||||
);
|
||||
OTHER_SWIFT_FLAGS = "-D DEBUG -D TRACE_RESOURCES";
|
||||
OTHER_SWIFT_FLAGS = "-D DEBUG -D TRACE_RESOURCES -D ENABLE_SWIZZLING";
|
||||
PRODUCT_NAME = RxTests;
|
||||
};
|
||||
name = Debug;
|
||||
|
|
@ -599,7 +599,7 @@
|
|||
"-framework",
|
||||
XCTest,
|
||||
);
|
||||
OTHER_SWIFT_FLAGS = "-D TRACE_RESOURCES";
|
||||
OTHER_SWIFT_FLAGS = "-D TRACE_RESOURCES -D ENABLE_SWIZZLING";
|
||||
PRODUCT_NAME = RxTests;
|
||||
};
|
||||
name = "Release-Tests";
|
||||
|
|
|
|||
Loading…
Reference in New Issue