Conversation
Yeonnies
reviewed
Dec 17, 2025
| import SwiftUI | ||
|
|
||
| struct DailyBoxOfficeView: View { | ||
| @StateObject var viewModel: DailyBoxOfficeViewModel_Combine |
Collaborator
There was a problem hiding this comment.
오 혹시 @ObjervedObject가 아닌 @StateObject 쓰신 이유가 있나요??
|
|
||
| import SwiftUI | ||
|
|
||
| protocol ViewModelType: ObservableObject { |
Collaborator
There was a problem hiding this comment.
왜 아웃풋은 따로 안만들어줬나요?? 바보 질문 미안..
| import Foundation | ||
|
|
||
| class DailyBoxOfficeViewModel_Combine: ViewModelType { | ||
| private let networkService = CombineBoxOfficeService() |
Collaborator
There was a problem hiding this comment.
싱글톤 패턴으로 서비스 만드셨던 거 같은데 굳이 만들어주신 이유가 있나요?? 바보 질문 죄송
Yeonnies
approved these changes
Dec 17, 2025
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.

🌀 컴바인 과제
📂 시연 영상
구현
처음에 그냥 Published + Task로 네트워크 호출을 했더니 컴바인을 안쓰게 되는 코드가 되더라구요
그래서 컴바인을 사용하는 버전, 안사용하는 버전 두가지의 뷰모델을 만들었습니다.
PR에서는 컴바인을 사용하는 버전만 작성합니다. + 저는 스유로 과제했습니다
네트워크
AnyPublisher를 리턴해줍니다. 퍼블리셔에서는 model 배열을 담고있습니다
뷰모델
저는 뷰모델타입 프로토콜을 채택해서 ViewModelType 프로토콜에서 ObservableObject를 채택해서 사용했습니다
퍼블리셔를 구독해서 Published 프로퍼티 객체에 해당 값을 바인딩해줍니다. 그러면 뷰에서 ui가 갱신되게 됩니다.
참고자료
https://medium.com/@catchvarun25/mvvm-with-swiftui-combine-51edb1a011ce