1

For example in the following code the default ObserverType has an event onError where Swift.Error object can be passed. How can I create custom ObserverType / Event so that I'll be able to supply an object of a custom class.

class LoginService: LoginServiceProtocol {
func signIn(with credentials: Credentials) -> Observable<User> {
    return Observable.create { observer in
        /*
         Networking logic here.
        */
        observer.onNext(User()) // Simulation of successful user authentication.
        observer.onError(<#T##error: Error##Error#>) // want to user custom class object instead of Swift.Error object here
        return Disposables.create()
    }
}
}
Pawan Joshi
  • 1,581
  • 3
  • 20
  • 40

1 Answers1

1

The only way to do it is to have the custom class object conform to the Swift.Error protocol.

class MyCustomClassObject: Error {
    // your custom stuff here
}
Daniel T.
  • 32,821
  • 6
  • 50
  • 72