μ λ€λ¦ ꡬ쑰체 | μμμ μ£Όμ΄μ§ μνμ€λ₯Ό λ°ννλ Publisher
μ΄λμ
λΌμ΄μ λ ν κ°μ μΈμλ₯Ό λ°λλ€.
sequence
: λ°νν μμκ° λ΄κΈ΄ μνμ€
sequence
λ Sequence
νλ‘ν μ½μ μ±νν΄μΌ νλ€. μλ¬ νμ
μ Error
νλ‘ν μ½μ μ±νν΄μΌ νλ€.
Publisherκ° μνμ€μ μλ μμλ€μ λͺ¨λ μ¬μ©νμμ λ λ€μ μμ²μμ Publisherκ° μ’
λ£νλ€.
μνμ€μ μλ μμλ€μ μ²μλΆν° νλνλ λ΄λ €μ£Όλ©°, λͺ¨λ μμλ₯Ό λ€ μ¬μ©νλ©΄ μ’
λ£νλ€.
Publishers.Sequence<[Int], Never>(sequence: [1, 2])
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Sequence Error")
case .finished:
print("Combine Sequence Finish")
}
}, receiveValue: {
print("Combine Sequence : \($0)")
})
.store(in: &cancellables)
// Combine Sequence : 1
// Combine Sequence : 2
// Combine Sequence Finish
RxSwift
from
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
Observable.from([1, 2])
.subscribe(onNext: {
print("RxSwift Sequence : \($0)")
}, onError: { _ in
print("RxSwift Sequence Error")
}, onCompleted: {
print("RxSwift Sequence Finish")
})
.disposed(by: disposeBag)
// RxSwift Sequence : 1
// RxSwift Sequence : 2
// RxSwift Sequence Finish
ReactiveSwift
init(_:)
μ΄λμ
λΌμ΄μ λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
SignalProducer([1, 2])
.start { event in
switch event {
case let .value(value):
print("ReactiveSwift Sequence : \(value)")
case .failed:
print("ReactiveSwift Sequence Error")
case .completed:
print("ReactiveSwift Sequence Finish")
default:
break
}
}
// ReactiveSwift Sequence : 1
// ReactiveSwift Sequence : 2
// ReactiveSwift Sequence Finish
μ°Έκ³
ReactiveX - Operators - From