-
Notifications
You must be signed in to change notification settings - Fork 0
I/O패턴 적용 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LJIN24
wants to merge
8
commits into
develop
Choose a base branch
from
LeeJinJae
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
I/O패턴 적용 #13
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6bab3a
[docs] README 수정
Rudy-009 cae5fc6
[feat] Factory Pattern 을 이용한 Root View 전환 관심사 분리
Rudy-009 a18ffcb
[feat] Factory 패턴 적용을 통한 TabBarController 의존성 분리 및 탭 전환 로직 구현
Rudy-009 9aae0a4
[feat] Moya 설치 및 네트워크 개발 환경 구축
Rudy-009 aabb399
I/O패턴 적용
LJIN24 27629e4
[merge] merge factory branch to leejinjae
LJIN24 c974ad8
[feat] 이전과제 리팩토링 및 새로운 과제 setup
LJIN24 f88e36e
[feat] 과제 complete
LJIN24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
Smashing-Assignment/Presentation/Jinjae/AppDIContainer.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // | ||
| // AppDIContainer.swift | ||
| // Smashing-Assignment | ||
| // | ||
| // Created by JIN on 1/4/26. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| class AppDIContainer { | ||
| static var shared: AppDIContainer = AppDIContainer() | ||
|
|
||
| func makeMainViewController() -> UIViewController { | ||
| let viewModel = HomeViewModel() | ||
| return JinJaeViewController(viewModel: viewModel) | ||
| } | ||
|
|
||
| } |
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
91 changes: 91 additions & 0 deletions
91
Smashing-Assignment/Presentation/Jinjae/HomeViewModel.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // | ||
| // HomeViewModel.swift | ||
| // Smashing-Assignment | ||
| // | ||
| // Created by JIN on 12/30/25. | ||
| // | ||
|
|
||
| import UIKit | ||
| import Combine | ||
|
|
||
| protocol InputOutputProtocol { | ||
|
|
||
| associatedtype Input | ||
| associatedtype Output | ||
|
|
||
| func transform(input: AnyPublisher<Input, Never>) -> AnyPublisher<Output, Never> | ||
|
|
||
| } | ||
|
|
||
|
|
||
| final class HomeViewModel: InputOutputProtocol { | ||
|
|
||
| enum Input { | ||
| case textFieldChanged(String) | ||
| case textField2Changed(String) | ||
| case submitButtonTapped | ||
| } | ||
|
|
||
| enum Output { | ||
| case updateButtonState(isEnabled: Bool) | ||
| case updateMessage(String) | ||
| case clearTextFields | ||
| } | ||
|
|
||
| // MARK: - Properties | ||
|
|
||
| private let output: PassthroughSubject<Output, Never> = .init() | ||
| private var cancellables = Set<AnyCancellable>() | ||
|
|
||
| private let text1Subject = CurrentValueSubject<String, Never>("") | ||
| private let text2Subject = CurrentValueSubject<String, Never>("") | ||
|
|
||
| // MARK: - Transform | ||
|
|
||
| func transform(input: AnyPublisher<Input, Never>) -> AnyPublisher<Output, Never> { | ||
| input.sink { [weak self] event in | ||
| guard let self = self else { return } | ||
| switch event { | ||
| case .textFieldChanged(let text): | ||
| self.text1Subject.send(text) | ||
|
|
||
| case .textField2Changed(let text): | ||
| self.text2Subject.send(text) | ||
|
|
||
| case .submitButtonTapped: | ||
| self.handleSubmitButtonTapped() | ||
| } | ||
| }.store(in: &cancellables) | ||
|
|
||
| Publishers.CombineLatest(text1Subject, text2Subject) | ||
| .map { text1, text2 in | ||
| return text1.count >= 5 && text2.count >= 5 | ||
| } | ||
| .removeDuplicates() | ||
| .sink { [weak self] isValid in | ||
| guard let self = self else { return } | ||
|
|
||
| self.output.send(.updateButtonState(isEnabled: isValid)) | ||
|
|
||
| if isValid { | ||
| self.output.send(.updateMessage("입력 완료")) | ||
| } else { | ||
| self.output.send(.updateMessage("두 필드 모두 5글자 이상 입력해주세요")) | ||
| } | ||
| } | ||
| .store(in: &cancellables) | ||
|
|
||
| return output.eraseToAnyPublisher() | ||
| } | ||
|
|
||
| // MARK: - Private Methods | ||
|
|
||
| private func handleSubmitButtonTapped() { | ||
| text1Subject.send("") | ||
| text2Subject.send("") | ||
| output.send(.clearTextFields) | ||
| output.send(.updateMessage("5글자 이상 입력해주세요")) | ||
| } | ||
| } | ||
|
|
||
|
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextDidChangedPublisher 사용해주세요