From 1c0475860aa47747c19b7950b1a2b504247736a0 Mon Sep 17 00:00:00 2001 From: Krunoslav Zaher Date: Sat, 13 Feb 2016 23:49:41 +0100 Subject: [PATCH] Fixes problem with required error. --- RxCocoa/Common/CLLocationManager+Rx.swift | 4 ++-- .../CLLocationManager+RxTests.swift | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/RxCocoa/Common/CLLocationManager+Rx.swift b/RxCocoa/Common/CLLocationManager+Rx.swift index 39e6a2fe..82a1a277 100644 --- a/RxCocoa/Common/CLLocationManager+Rx.swift +++ b/RxCocoa/Common/CLLocationManager+Rx.swift @@ -49,10 +49,10 @@ extension CLLocationManager { /** Reactive wrapper for `delegate` message. */ - public var rx_didFinishDeferredUpdatesWithError: Observable { + public var rx_didFinishDeferredUpdatesWithError: Observable { return rx_delegate.observe("locationManager:didFinishDeferredUpdatesWithError:") .map { a in - return try castOrThrow(NSError.self, a[1]) + return try castOptionalOrThrow(NSError.self, a[1]) } } #endif diff --git a/Tests/RxCocoaTests/CLLocationManager+RxTests.swift b/Tests/RxCocoaTests/CLLocationManager+RxTests.swift index a016fee8..5831af34 100644 --- a/Tests/RxCocoaTests/CLLocationManager+RxTests.swift +++ b/Tests/RxCocoaTests/CLLocationManager+RxTests.swift @@ -84,6 +84,26 @@ extension CLLocationManagerTests { XCTAssertTrue(completed) } + func testDidFinishDeferredUpdatesWithError_noError() { + var completed = false + var error: NSError? + + autoreleasepool { + let manager = CLLocationManager() + + _ = manager.rx_didFinishDeferredUpdatesWithError.subscribe(onNext: { e in + error = e + }, onCompleted: { + completed = true + }) + + manager.delegate!.locationManager!(manager, didFinishDeferredUpdatesWithError: nil) + } + + XCTAssertEqual(error, nil) + XCTAssertTrue(completed) + } + #endif #if os(iOS)