Publishers.First
์ ๋ค๋ฆญ ๊ตฌ์กฐ์ฒด | ์คํธ๋ฆผ์ ์ฒซ ๋ฒ์งธ ์์๋ฅผ ๋ฐํํ๊ณ ์ข ๋ฃํ๋ Publisher
์ด๋์ ๋ผ์ด์ ๋ ํ ๊ฐ์ ์ธ์๋ฅผ ๋ฐ๋๋ค.
upstream: ์์์ ํ๋ฅด๋ Publisher
first ์คํผ๋ ์ดํฐ์ ๊ด๋ จ์ด ์๋ค.
// 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์ ๊ฐ์ ์ฐจ๋ก๋๋ก ๋ธ๋ค.
first์ ์ํด ์ฒซ ๋ฒ์งธ ์์๋ง ๋ฐํ๋๋ฉฐ, ๊ฒฐ๊ณผ์ ์ผ๋ก 1์ ๊ฐ์ ๋ด๊ณ ์ข
๋ฃํ๋ค.
RxSwift
first ์คํผ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌํํ ์ ์๋ค.
ReactiveSwift
first ์คํผ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌํํ ์ ์๋ค.
์ฐธ๊ณ
Last updated
Was this helpful?