THIS IS ELLIE

Combine 시작하기 본문

개발/Combine

Combine 시작하기

Ellie Kim 2020. 3. 3. 13:45

WWDC 2019에서 Introducting Combine에 대해서 발표가 나왔다.

https://developer.apple.com/videos/play/wwdc2019/722

 

Combine 프레임워크는 시간에 지남에 따라 값을 처리하기 위한 선언적인 스위프트 API를 제공한다.

 

Combine의 특징

- Generic

- Type safe

- Composition first

- Request driven

 

Combine은 이와 같은 비동기적인 인터페이스들에 사용하면 편리하다

- Target / Action

- Notification center

- URLSession

- Key-value observing

- Ad-hoc callbacks

 

Combine에는 Publisher, Subscriber, Operator이 핵심이다.

Publisher는 시간이 지남에 따라 변경될 수 있는 값을 방출하고

Subscriber은 Publisher로부터 해당 값을 받도록 선언한다.

Operator은 값을 변경하기 위해 존재한다.

 

Publisher과 Subscriber사이의 패턴

resource: https://developer.apple.com/videos/play/wwdc2019/722

Subscriber가 Publisher를 구독한다.

Publisher은 Subscription을 보낸다.

Subscriber은 N value를 요청한다.

Publisher은 N의 value나 적게보낸다.

publisher는 completion을 보낸다.

 

Combine을 사용하는 이유

Combine을 채택하면 이벤트 처리 코드를 집중화하고,

중첩 클로저들 컨벤션 기반 콜백 기술을 없애 코드를 읽기 쉽게 읽고 유지보수할 수 있다.

반응형

'개발 > Combine' 카테고리의 다른 글

Publisher, Subscriber, Operator  (0) 2020.03.03
Combine provides a declarative Swift API . . .  (0) 2020.03.03