Open
Conversation
y-eonee
approved these changes
Dec 17, 2025
| } | ||
|
|
||
| func bindViewModel() { | ||
| let output = viewModel.transform(input: inputSubject.eraseToAnyPublisher()) |
Member
There was a problem hiding this comment.
뷰모델에서 eraseToAnyPublisher를 처리해서 뷰컨으로 보내주는 방법도 있을 것 같아요!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. 화면 영상
2. URLSession.shared.dataTaskPublisher
주어진 URL에 대한 URLSession 응답을 개시하는 Publisher를 반환한다. (URLRequest도 사용가능하다. 좀 더, 복잡한 RestAPI 에 사용)
(data: Data, response: URLResponse)Element의 형태map업스트림 퍼블리셔를 제공된 클로저를 이용해서 변환(가공)한다.
keyPath를 이용하여, data 부분만을 반환한다.
3. Throttling / Debouncing
Throttling
일정 시간 동안 이벤트를 한 번만 실행되도록 제어하는 것
주로, 무한 스크롤에서 사용된다. 스크롤 위치가 여러번 감지 되었을 때, GET 호출을 제어해야 한다. 그렇지 않으면 매우 많은 호출이 발생할 수 있다.
Debouncing
연이어 호출되는 함수들 중 마지막 함수(또는 제일 처음)만 호출하도록 하는 것
검색 시, 키보드 입력 이후, 일정 시간이 지날 때, 검색이 되도록 만들 수 있다.
4. Combine에서 Throttling / Debouncing
Debouncing을 이용한 검색
검색 TextField의 입력 수정 Publisher에서 입력 변화에 대해 바로 API를 호출하는 것이 아닌, debouncing을 통해 API 호출을 제안할 수 있다.
Throttling
5. Input/Output 패턴과 맞는가?
호출 횟수 제한은 ViewController와 ViewModel 둘 중 어디에 책임이 있는지 생각해보면 ViewModel가 더 맞다고 생각한다. 하지만, 아직 Combine에 대한 이해가 부족하여, 부득이하게 ViewController에서 구현했다.
원인 input 분리에 대한 낮은 이해도가 원인이었다.
flatMap
flatMap이란? 업스트림의 요소들에 개별적으로 접근하여 새로운 퍼블리셔로 전환하다. 이 부분에서 막혔다.
debounce가 적용이 안된다…. 왜 그럴까…
제미나이 왈) "매번 새로운 스트림이 생성됨"
flatMap내부에서Just(input)를 생성하는 순간, 오직 값 하나만 들어있는 새로운 파이프라인이 만들어집니다.flatMap이 실행됨.Just통로를 만듦.throttle을 걸었지만, 어차피 데이터가 하나뿐이라 기다릴 것 없이 즉시 통과됨.“결과적으로 모든 신호가 각각의 "1인용 통로"를 타고 그대로 통과되어 버립니다.”