coolly coolly - 6 months ago 18
iOS Question

How to get error value from a subscribed RACSignal?

For example:

In one controller, implementation

func sendSuccessOrNot()->RACSignal {
// code here
}


In another controller, calling that signal

controller.sendSuccessOrNot().subscribeNext {

}


how to check in the above calling if sendSuccessOrNot is sending error or success value in ReactiveCocoa.

Answer

The syntax you use makes me think you're using Swift, in which case you shouldn't be using RACSignal, you should be converting your RACSignal to a SignalProducer with .toSignalProducer()

controller.sendSuccessOrNot().toSignalProducer().on(next: { value in
    print("next: \(value)")
}, 
failed: { error in
    print("failed: \(error)")
}).start()

If you're still using RAC 2 then it'd be

controller.sendSuccessOrNot().subscribeNext({ value in
    print("next: \(value)")
}, error: { error in
    print("failed: \(error)")
})