iOS/RxSwift
[iOS/RxSwift] Next, Error, Completed 처리하기
여성일
2024. 2. 3. 20:56
728x90
우리가 observable을 생성하고 subscribe할 때 onNext, onError, onCompleted, onDisposed 클로저를 인자로 넘겨주는 방식을 가장 많이 사용할 것이고 사용했지만, 이번에는 subscribe(_ on:)에 대해 알아볼 것이다.
subscribe(_ on:)은 인자로 Event Type을 받아온다.
Event Type은 enum으로 completed, error, next 총 세 개의 case가 있다.
✅ next : Next element is produced.
➡️ 다음 요소를 생성합니다.
✅ error : Sequence terminated with an error.
➡️ 시퀀스에 오류가 발생했습니다.
✅ completed : Sequence completed successfully.
➡️ 시퀀스가 성공적으로 완료되었습니다.
코드를 실행하면
위와 같이 실행된다.