Skip to content

Commit

Permalink
Merge pull request #13 from ReactiveCocoa/anyerror
Browse files Browse the repository at this point in the history
Utilize AnyError
  • Loading branch information
mdiep authored Dec 27, 2016
2 parents acef994 + 283444d commit 9931a7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions ReactiveObjCBridge/ObjectiveCBridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ private func defaultNSError(_ message: String, file: String, line: Int) -> NSErr
/// - line: Current line in file.
///
/// - returns: Signal producer created from the provided signal.
public func bridgedSignalProducer<Value>(from signal: RACSignal<Value>, file: String = #file, line: Int = #line) -> SignalProducer<Value?, NSError> {
return SignalProducer<Value?, NSError> { observer, disposable in
public func bridgedSignalProducer<Value>(from signal: RACSignal<Value>, file: String = #file, line: Int = #line) -> SignalProducer<Value?, AnyError> {
return SignalProducer<Value?, AnyError> { observer, disposable in
let next: (_ value: Value?) -> Void = { obj in
observer.send(value: obj)
}

let failed: (_ nsError: Swift.Error?) -> () = {
observer.send(error: ($0 as? NSError) ?? defaultNSError("Nil RACSignal error", file: file, line: line))
let failed: (_ error: Swift.Error?) -> () = { error in
observer.send(error: AnyError(error ?? defaultNSError("Nil RACSignal error", file: file, line: line)))
}

let completed = {
Expand Down Expand Up @@ -279,14 +279,14 @@ extension ActionProtocol {
/// - line: Current line in file.
///
/// - returns: Action created from `self`.
public func bridgedAction<Input, Output>(from command: RACCommand<Input, Output>, file: String = #file, line: Int = #line) -> Action<Input?, Output?, NSError> {
public func bridgedAction<Input, Output>(from command: RACCommand<Input, Output>, file: String = #file, line: Int = #line) -> Action<Input?, Output?, AnyError> {
let enabledProperty = MutableProperty(true)

enabledProperty <~ bridgedSignalProducer(from: command.enabled)
.map { $0 as! Bool }
.flatMapError { _ in SignalProducer<Bool, NoError>(value: false) }

return Action<Input?, Output?, NSError>(enabledIf: enabledProperty) { input -> SignalProducer<Output?, NSError> in
return Action<Input?, Output?, AnyError>(enabledIf: enabledProperty) { input -> SignalProducer<Output?, AnyError> in
let signal: RACSignal<Output> = command.execute(input)

return bridgedSignalProducer(from: signal)
Expand Down
6 changes: 3 additions & 3 deletions ReactiveObjCBridgeTests/ObjectiveCBridgingSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ class ObjectiveCBridgingSpec: QuickSpec {
}

it("should forward errors") {
let error = TestError.default as NSError
let error = TestError.default

let racSignal = RACSignal<AnyObject>.error(error)
let producer = bridgedSignalProducer(from: racSignal)
let result = producer.last()

expect(result?.error) == error
expect(result?.error) == AnyError(error)
}
}

Expand Down Expand Up @@ -214,7 +214,7 @@ class ObjectiveCBridgingSpec: QuickSpec {
var enabledSubject: RACSubject!
var enabled = false

var action: Action<NSNumber?, NSNumber?, NSError>!
var action: Action<NSNumber?, NSNumber?, AnyError>!

beforeEach {
enabledSubject = RACSubject()
Expand Down
7 changes: 7 additions & 0 deletions ReactiveObjCBridgeTests/TestError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ internal enum TestError: Int {
extension TestError: Error {
}

extension AnyError: Equatable {
public static func ==(lhs: AnyError, rhs: AnyError) -> Bool {
return lhs.error._code == rhs.error._code
&& lhs.error._domain == rhs.error._domain
}
}


internal extension SignalProducerProtocol {
/// Halts if an error is emitted in the receiver signal.
Expand Down

0 comments on commit 9931a7e

Please sign in to comment.