Updated to 1.7

This commit is contained in:
Krunoslav Zaher 2015-07-20 19:19:02 +02:00
parent 8d3533caf6
commit bd284c8269
8 changed files with 21 additions and 20 deletions

View File

@ -22,7 +22,7 @@ public func toArray<E>(source: Observable<E>)
source.subscribeSafe(AnonymousObserver { e in
switch e {
case .Next(let element):
elements.append(element.value)
elements.append(element)
case .Error(let e):
error = e
condition.lock()
@ -65,7 +65,7 @@ public func first<E>(source: Observable<E>)
switch e {
case .Next(let e):
if element == nil {
element = e.value
element = e
}
break
case .Error(let e):
@ -109,7 +109,7 @@ public func last<E>(source: Observable<E>)
d.disposable = source.subscribeSafe(AnonymousObserver { e in
switch e {
case .Next(let e):
element = e.value
element = e
return
case .Error(let e):
error = e

View File

@ -46,14 +46,14 @@ class KVOObservable<Element> : Producer<Element?>
#if !DISABLE_SWIZZLING
func observeWeaklyKeyPathFor(target: NSObject, # keyPath: String, # options: NSKeyValueObservingOptions) -> Observable<AnyObject?> {
func observeWeaklyKeyPathFor(target: NSObject, keyPath: String, options: NSKeyValueObservingOptions) -> Observable<AnyObject?> {
let components = keyPath.componentsSeparatedByString(".").filter { $0 != "self" }
let observable = observeWeaklyKeyPathFor(target, keyPathSections: components, options: options)
>- distinctUntilChanged { $0 === $1 }
>- finishWithNilWhenDealloc(target)
if options & .Initial != .allZeros {
if !options.intersect(.Initial).isEmpty {
return observable
}
else {
@ -86,8 +86,8 @@ func finishWithNilWhenDealloc(target: NSObject)
func observeWeaklyKeyPathFor(
target: NSObject,
# keyPathSections: [String],
# options: NSKeyValueObservingOptions
keyPathSections: [String],
options: NSKeyValueObservingOptions
) -> Observable<AnyObject?> {
weak var weakTarget: AnyObject? = target
@ -103,7 +103,7 @@ func observeWeaklyKeyPathFor(
// should dealloc hook be in place if week property, or just create strong reference because it doesn't matter
let isWeak = isWeakProperty(String.fromCString(propertyAttributes) ?? "")
let propertyObservable = KVOObservable(object: target, keyPath: propertyName, options: options | .Initial, retainTarget: false) as KVOObservable<AnyObject>
let propertyObservable = KVOObservable(object: target, keyPath: propertyName, options: options.union(.Initial), retainTarget: false) as KVOObservable<AnyObject>
// KVO recursion for value changes
return propertyObservable

View File

@ -41,7 +41,7 @@ extension NSObject {
// Observes values on `keyPath` starting from `self` with `.Initial | .New` options.
// Retains `self` while observing.
public func rx_observe<Element>(keyPath: String) -> Observable<Element?> {
return KVOObservable(object: self, keyPath: keyPath, options: .Initial | .New, retainTarget: true)
return KVOObservable(object: self, keyPath: keyPath, options: NSKeyValueObservingOptions.Initial.union(NSKeyValueObservingOptions.New), retainTarget: true)
}
// Observes values on `keyPath` starting from `self` with `options`
@ -62,7 +62,7 @@ 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?> {
return rx_observeWeakly(keyPath, options: .New | .Initial)
return rx_observeWeakly(keyPath, options: NSKeyValueObservingOptions.New.union(.Initial))
}
// Observes values on `keyPath` starting from `self` with `options`
@ -90,8 +90,8 @@ extension NSObject {
sendNext(subject, ())
sendCompleted(subject)
}
objc_setAssociatedObject(self, &deallocatedSubjectContext, subject, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
objc_setAssociatedObject(self, &deallocatedSubjectTriggerContext, deinitAction, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
objc_setAssociatedObject(self, &deallocatedSubjectContext, subject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
objc_setAssociatedObject(self, &deallocatedSubjectTriggerContext, deinitAction, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return subject
}
}
@ -113,7 +113,7 @@ extension NSObject {
self,
&deallocatingSubjectContext,
subject,
objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC)
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
let proxy = Deallocating {
@ -127,12 +127,12 @@ extension NSObject {
objc_setAssociatedObject(self,
RXDeallocatingAssociatedAction,
proxy,
objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC)
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
objc_setAssociatedObject(self,
&deallocatingSubjectTriggerContext,
deinitAction,
objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC)
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
RX_ensure_deallocating_swizzled(self.dynamicType)

View File

@ -31,7 +31,7 @@ extension UIControl {
sendNext(observer, getValue())
let controlTarget = ControlTarget(control: self, controlEvents: UIControlEvents.EditingChanged | .ValueChanged) { control in
let controlTarget = ControlTarget(control: self, controlEvents: UIControlEvents.EditingChanged.union(.ValueChanged)) { control in
sendNext(observer, getValue())
}

View File

@ -24,7 +24,7 @@ extension UIImageView {
switch event {
case .Next(let boxedValue):
let value = boxedValue.value
let value = boxedValue
if animated && value != nil {
let transition = CATransition()
transition.duration = 0.25

View File

@ -19,7 +19,7 @@ extension UISearchBar {
}
public var rx_searchText: Observable<String> {
return defer { [weak self] in
return deferred { [weak self] in
let text = self?.text ?? ""
return self?.rx_delegate.observe("searchBar:textDidChange:") ?? empty()

View File

@ -30,7 +30,7 @@ class Parent : NSObject {
init(callback: String? -> Void) {
super.init()
self.rx_observe("val", options: .Initial | .New, retainSelf: false)
self.rx_observe("val", options: NSKeyValueObservingOptions.Initial.union(.New), retainSelf: false)
>- subscribeNext(callback)
>- disposeBag.addDisposable
}
@ -45,7 +45,7 @@ class Child : NSObject {
init(parent: ParentWithChild, callback: String? -> Void) {
super.init()
parent.rx_observe("val", options: .Initial | .New, retainSelf: false)
parent.rx_observe("val", options: NSKeyValueObservingOptions.Initial.union(.New), retainSelf: false)
>- subscribeNext(callback)
>- disposeBag.addDisposable
}

View File

@ -8,6 +8,7 @@
import XCTest
import RxSwift
import CoreLocation
#if TRACE_RESOURCES
#elseif RELEASE