Combine

Combine은 비동기 및 이벤트 처리 코드를 작성하는데 사용되는 프레임워크 입니다.

이전에 반응형 프로그래밍으로 RxSwift를 사용해 본 적이 있는데, 애플에서 개발한 Combine도 있다고 하여 개념을 정리해보고자 합니다

 

 

Publisher: 값을 생성하고 전달하는 객체입니다.

public protocol Publisher {
    associatedtype Output
    associatedtype Failure: Error

    func receive<S>(subscriber: S) where S : Subscriber, Self.Failure == S.Failure, Self.Output == S.Input
}

 

Subscriber: Publisher로부터 데이터를 수신하고 처리하는 객체입니다.

public protocol Subscriber: CustomCombineIdentifierConvertible {
    associatedtype Input
    associatedtype Failure: Error

    func receive(subscription: Subscription)
    func receive(_ input: Self.Input) -> Subscribers.Demand
    func receive(completion: Subscribers.Completion<Self.Failure>)
}

Operators: Publisher로부터 전달받은 값을 변환하거나 조작하는 객체입니다.

 

Combine의 흐름은 Publisher -> Operator -> Subscriber 순으로 진행됩니다.

 

 

'iOS' 카테고리의 다른 글

UIBeizerPath  (0) 2025.02.26
NotificationCenter  (0) 2025.02.20
URLSession 번역  (0) 2024.12.13
Fetching website data into memory  (0) 2024.12.10
URL Loading System 번역  (2) 2024.12.10

+ Recent posts