μ΄λμ
λΌμ΄μ λ ν κ°μ μΈμλ₯Ό λ°λλ€.
// Publishers.First Publisher
Publishers
.First(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3, 4, 5]))
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine First Error")
case .finished:
print("Combine First Finish")
}
}, receiveValue: { value in
print("Combine First : \(value)")
})
.store(in: &cancellables)
// first Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3, 4, 5])
.first()
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine First Error")
case .finished:
print("Combine First Finish")
}
}, receiveValue: { value in
print("Combine First : \(value)")
})
.store(in: &cancellables)
// Combine First : 1
// Combine First Finish
μμ Publisherλ 1, 2, 3, 4, 5μ κ°μ μ°¨λ‘λλ‘ λΈλ€.
Observable.from([1, 2, 3, 4, 5])
.first()
.subscribe(onSuccess: { value in
print("RxSwift First : \(value)")
}, onError: { _ in
print("RxSwift First Error")
})
.disposed(by: disposeBag)
// RxSwift First : Optional(1)
SignalProducer([1, 2, 3])
.first()?.signal
.observe { event in
switch event {
case let .value(value):
print("ReactiveSwift First : \(value)")
case .failed:
print("ReactiveSwift First Error")
case .completed:
print("ReactiveSwift First Finish")
default:
break
}
}
// ReactiveSwift First : 1
// ReactiveSwift First Finish