generated from GO-SOPT-iOS-Part/KimSeungChan
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] MVVM 패턴으로 이메일 형식, 비밀번호 형식 유효할때 로그인버튼 활성화 #10
- Loading branch information
Showing
6 changed files
with
91 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
55 changes: 55 additions & 0 deletions
55
SOPTving/SOPTving/Presentation/AuthScene/ViewModel/SignInViewModel.swift
This file contains 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,55 @@ | ||
// | ||
// SignInViewModel.swift | ||
// SOPTving | ||
// | ||
// Created by 장석우 on 2023/04/28. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol SignInViewModelInput { | ||
func idTextFieldDidChangeEvent(_ text: String) | ||
func passwordTextFieldDidChangeEvent(_ text: String) | ||
} | ||
|
||
protocol SignInViewModelOutput { | ||
var isValidEmail: Observable<Bool> { get } | ||
var isValidPassword: Observable<Bool> { get } | ||
var ableToLogin: Observable<Bool> { get } | ||
} | ||
|
||
protocol SignInViewModel: SignInViewModelInput, SignInViewModelOutput { } | ||
|
||
final class DefaultSignInViewModel: SignInViewModel { | ||
|
||
private var email: String | ||
private var password: String | ||
|
||
//MARK: - Output | ||
|
||
var isValidEmail: Observable<Bool> = Observable(false) | ||
var isValidPassword: Observable<Bool> = Observable(false) | ||
var ableToLogin: Observable<Bool> = Observable(false) | ||
|
||
//MARK: - Init | ||
|
||
init(email: String, password: String) { | ||
self.email = email | ||
self.password = password | ||
} | ||
|
||
} | ||
|
||
extension DefaultSignInViewModel { | ||
|
||
func idTextFieldDidChangeEvent(_ text: String) { | ||
self.isValidEmail.value = text.isEmailFormat && text.isMoreThan(8) | ||
self.ableToLogin.value = isValidEmail.value && isValidPassword.value | ||
} | ||
|
||
func passwordTextFieldDidChangeEvent(_ text: String) { | ||
self.isValidPassword.value = text.isMoreThan(8) | ||
self.ableToLogin.value = isValidEmail.value && isValidPassword.value | ||
} | ||
|
||
} |
This file contains 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
This file contains 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