Publishers.Count
์ ๋ค๋ฆญ ๊ตฌ์กฐ์ฒด | ์์์ ํ๋ฅด๋ Publisher๋ก๋ถํฐ ์ ๋ฌ๋ฐ์ ์์๋ค์ ๊ฐ์๋ฅผ ๋ฐํํ๋ Publisher
์ด๋์ ๋ผ์ด์ ๋ ํ ๊ฐ์ ์ธ์๋ฅผ ๋ฐ๋๋ค.
upstream: ์์์ ํ๋ฅด๋ Publisher
์์ Publisher๊ฐ ๋ฐํํ๋ ์์์ ๊ฐ์๋ฅผ ๋ฐฐ์ถํ๋ค.
count ์คํผ๋ ์ดํฐ์ ๊ด๋ จ์ด ์๋ค.
// Publishers.Count Publisher
Publishers
  .Count(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3]))
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine Count Error")
    case .finished:
      print("Combine Count Finish")
    }
  }, receiveValue: { value in
    print("Combine Count : \(value)")
  })
  .store(in: &cancellables)
// count Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3])
  .count()
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine Count Error")
    case .finished:
      print("Combine Count Finish")
    }
  }, receiveValue: { value in
    print("Combine Count : \(value)")
  })
  .store(in: &cancellables)
// Combine Count : 3
// Combine Count Finish์์ Publisher์ ํ๋ฅด๋ ๊ฐ์ ๊ฐ์๊ฐ 3์ด๋ฏ๋ก ์ต์ข ์ ์ผ๋ก 3์ ๊ฐ์ ๋ด๊ณ ์ข ๋ฃํ๋ค.
RxSwift
ํด๋น ๋์์ ๊ตฌํํ๊ธฐ ์ํ ์คํผ๋ ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์๋๋ค.
ReactiveSwift
ํด๋น ๋์์ ๊ตฌํํ๊ธฐ ์ํ ์คํผ๋ ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์๋๋ค.
์ฐธ๊ณ 
Last updated
Was this helpful?