Skip to content

Commit

Permalink
Removing swift3 compile checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianoPAlmeida authored and kzaher committed Dec 21, 2018
1 parent 1195554 commit b51493f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 90 deletions.
14 changes: 1 addition & 13 deletions Platform/DataStructures/PriorityQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ struct PriorityQueue<Element> {
private mutating func removeAt(_ index: Int) {
let removingLast = index == _elements.count - 1
if !removingLast {
#if swift(>=3.2)
_elements.swapAt(index, _elements.count - 1)
#else
swap(&_elements[index], &_elements[_elements.count - 1])
#endif
}

_ = _elements.popLast()
Expand All @@ -76,11 +72,7 @@ struct PriorityQueue<Element> {
while unbalancedIndex > 0 {
let parentIndex = (unbalancedIndex - 1) / 2
guard _hasHigherPriority(_elements[unbalancedIndex], _elements[parentIndex]) else { break }
#if swift(>=3.2)
_elements.swapAt(unbalancedIndex, parentIndex)
#else
swap(&_elements[unbalancedIndex], &_elements[parentIndex])
#endif
unbalancedIndex = parentIndex
}
}
Expand All @@ -105,12 +97,8 @@ struct PriorityQueue<Element> {
}

guard highestPriorityIndex != unbalancedIndex else { break }

#if swift(>=3.2)
_elements.swapAt(highestPriorityIndex, unbalancedIndex)
#else
swap(&_elements[highestPriorityIndex], &_elements[unbalancedIndex])
#endif

unbalancedIndex = highestPriorityIndex
}
}
Expand Down
46 changes: 22 additions & 24 deletions RxCocoa/Common/KeyPathBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@
// Copyright © 2018 Krunoslav Zaher. All rights reserved.
//

#if swift(>=3.2)
import RxSwift
import RxSwift

extension Reactive where Base: AnyObject {

extension Reactive where Base: AnyObject {

/// Bindable sink for arbitrary property using the given key path.
/// Binding runs on the MainScheduler.
///
/// - parameter keyPath: Key path to write to the property.
public subscript<Value>(keyPath: ReferenceWritableKeyPath<Base, Value>) -> Binder<Value> {
return Binder(self.base) { base, value in
base[keyPath: keyPath] = value
}
/// Bindable sink for arbitrary property using the given key path.
/// Binding runs on the MainScheduler.
///
/// - parameter keyPath: Key path to write to the property.
public subscript<Value>(keyPath: ReferenceWritableKeyPath<Base, Value>) -> Binder<Value> {
return Binder(self.base) { base, value in
base[keyPath: keyPath] = value
}
/// Bindable sink for arbitrary property using the given key path.
/// Binding runs on the specified scheduler.
///
/// - parameter keyPath: Key path to write to the property.
/// - parameter scheduler: Scheduler to run bindings on.
public subscript<Value>(keyPath: ReferenceWritableKeyPath<Base, Value>, on scheduler: ImmediateSchedulerType) -> Binder<Value> {
return Binder(self.base, scheduler: scheduler) { base, value in
base[keyPath: keyPath] = value
}
}

/// Bindable sink for arbitrary property using the given key path.
/// Binding runs on the specified scheduler.
///
/// - parameter keyPath: Key path to write to the property.
/// - parameter scheduler: Scheduler to run bindings on.
public subscript<Value>(keyPath: ReferenceWritableKeyPath<Base, Value>, on scheduler: ImmediateSchedulerType) -> Binder<Value> {
return Binder(self.base, scheduler: scheduler) { base, value in
base[keyPath: keyPath] = value
}

}
#endif

}
6 changes: 1 addition & 5 deletions RxExample/RxExample/Services/ReachabilityService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

import RxSwift

#if swift(>=3.2)
import class Dispatch.DispatchQueue
#else
import class Dispatch.queue.DispatchQueue
#endif
import class Dispatch.DispatchQueue

public enum ReachabilityStatus {
case reachable(viaWiFi: Bool)
Expand Down
91 changes: 43 additions & 48 deletions Tests/RxCocoaTests/KeyPathBinder+RxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,61 @@
// Copyright © 2018 Krunoslav Zaher. All rights reserved.
//

#if swift(>=3.2)
import RxCocoa
import RxSwift
import XCTest

final class KeyPathBinderTests: RxTest {}

private final class Object: ReactiveCompatible {
var value: Int = 0 {
didSet { valueDidSet() }
}

import RxCocoa
import RxSwift
import XCTest
private let valueDidSet: () -> Void

final class KeyPathBinderTests: RxTest {}
init(valueDidSet: @escaping () -> Void) {
self.valueDidSet = valueDidSet
}
}

extension KeyPathBinderTests {

private final class Object: ReactiveCompatible {
var value: Int = 0 {
didSet { valueDidSet() }
func testBindingOnNonMainQueueDispatchesToMainQueue() {
let waitForElement = self.expectation(description: "wait until element arrives")

let object = Object {
MainScheduler.ensureExecutingOnScheduler()
waitForElement.fulfill()
}

private let valueDidSet: () -> Void
let bindingObserver = object.rx[\.value]

DispatchQueue.global(qos: .default).async {
bindingObserver.on(.next(1))
}

init(valueDidSet: @escaping () -> Void) {
self.valueDidSet = valueDidSet
self.waitForExpectations(timeout: 1.0) { (e) in
XCTAssertNil(e)
}
}

extension KeyPathBinderTests {
func testBindingOnMainQueueDispatchesToNonMainQueue() {
let waitForElement = self.expectation(description: "wait until element arrives")

func testBindingOnNonMainQueueDispatchesToMainQueue() {
let waitForElement = self.expectation(description: "wait until element arrives")

let object = Object {
MainScheduler.ensureExecutingOnScheduler()
waitForElement.fulfill()
}

let bindingObserver = object.rx[\.value]

DispatchQueue.global(qos: .default).async {
bindingObserver.on(.next(1))
}

self.waitForExpectations(timeout: 1.0) { (e) in
XCTAssertNil(e)
}
let object = Object {
XCTAssert(!DispatchQueue.isMain)
waitForElement.fulfill()
}

func testBindingOnMainQueueDispatchesToNonMainQueue() {
let waitForElement = self.expectation(description: "wait until element arrives")

let object = Object {
XCTAssert(!DispatchQueue.isMain)
waitForElement.fulfill()
}

let scheduler = ConcurrentDispatchQueueScheduler(qos: .default)
let bindingObserver = object.rx[\.value, on: scheduler]

bindingObserver.on(.next(1))

self.waitForExpectations(timeout: 1.0) { (e) in
XCTAssertNil(e)
}
}
let scheduler = ConcurrentDispatchQueueScheduler(qos: .default)
let bindingObserver = object.rx[\.value, on: scheduler]

bindingObserver.on(.next(1))

self.waitForExpectations(timeout: 1.0) { (e) in
XCTAssertNil(e)
}
}

#endif

}

0 comments on commit b51493f

Please sign in to comment.