์ ๋ค๋ฆญ ๊ตฌ์กฐ์ฒด | ํ์
์ ์ง์ด Publisher
์ด๋์
๋ผ์ด์ ๋ ํ ๊ฐ์ ์ธ์๋ฅผ ๋ฐ๋๋ค.
upstream : ํ์
์ ์ง์ฐ๊ณ ์ถ์ Publisher
Subscriber๋ ๋ค๋ฅธ Publisher์๊ฒ Publisher์ ์์ธ ํ์
์ ๋
ธ์ถํ๊ณ ์ถ์ง ์์ ๋ ํน์ Publisher๋ฅผ AnyPublisher์ ๋ํํ์ฌ ์ฌ์ฉํ๋ค.
Combine์์๋ ๊ฐ๊ฐ์ Publisher๊ฐ Just, Fail, Publishers.Map๊ณผ ๊ฐ์ ๋ณ๋์ ํ์
์ ๊ฐ์ง๋ฉฐ, ๊ฐ ์คํผ๋ ์ดํฐ ๋ํ ๋ณ๋์ ํ์
์ ๋ฐํํ๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ต์ข
๊ฒฐ๊ณผ๋ ํ์
์ ์ง์์ ์ธ๋ถ์ ๋
ธ์ถํ ํ์๊ฐ ์๋ค.
eraseToAnyPublisher ์คํผ๋ ์ดํฐ์ ๊ด๋ จ์ด ์๋ค.
func combinePublisher() -> AnyPublisher<Void, Never> {
Just(Void()).eraseToAnyPublisher()
}
combinePublisher()
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine AnyPublisher Error")
case .finished:
print("Combine AnyPublisher Finish")
}
}, receiveValue: {
print("Combine AnyPublisher")
})
.store(in: &cancellables)
// Combine AnyPublisher
// Combine AnyPublisher Finish
RxSwift์ ๊ฐ ์คํผ๋ ์ดํฐ๋ Observable์ ๊ฐ์ด๋ ์๋ฌ์ ์ ๋ค๋ฆญ ํ์
์ ๋ฐ๊พธ๋ ๊ฒ์ผ๋ก ๋์ํ๊ธฐ ๋๋ฌธ์ ํ์
์ ์ง์ธ ํ์๊ฐ ์๋ค. Observable์ด AnyPublisher์ ์ญํ ์ ํ๋ ๊ฒ์ด๋ค.
ReactiveSwift์ ๊ฐ ์คํผ๋ ์ดํฐ๋ Signal์ด๋ SignalProducer์ ๊ฐ์ด๋ ์๋ฌ์ ์ ๋ค๋ฆญ ํ์
์ ๋ฐ๊พธ๋ ๊ฒ์ผ๋ก ๋์ํ๊ธฐ ๋๋ฌธ์ ํ์
์ ์ง์ธ ํ์๊ฐ ์๋ค. Signal๊ณผ SignalProducer๊ฐ AnyPublisher์ ์ญํ ์ ํ๋ ๊ฒ์ด๋ค.
Wikipedia - Type erasure