*UI 프로퍼티 외의 프로퍼티들은 view model에서 처리
*viewController에는 UI관련 로직만
// **ViewModel ============================================================**
final class **LoginViewModel**: NSObject {
/// 애플 로그인
func handleAppleLogin(with vc: LoginVC) {
AppleService.shared.startSignInWithAppleFlow(view: vc)
}
/// 구글 로그인
func handleGoogleLogin(with vc: LoginVC) {
GoogleService.shared.startSignInWithGoogleFlow(with: vc)
}
}
// **ViewController ======================================================**
class LoginVC: UIViewController {
var isAgreed = false
@objc func tapGoogleButton() {
guard isAgreed == true else {
CommonUtil.showAlert(title: "이용 약관을 동의해주세요", message: nil, actionTitle: "확인", actionStyle: .default) { _ in return }
return
}
GoogleService.shared.startSignInWithGoogleFlow(with: self)
}
}
// **ViewModel ============================================================**
final class LoginViewModel: NSObject {
//MARK: - properties ==================
var **isAgreed** = false
/// 구글 로그인
func **handleGoogleLogin**(with vc: LoginVC) {
if isAgreed == true {
GoogleService.shared.startSignInWithGoogleFlow(with: vc)
} else {
showTermsAgreeAlert()
}
}
/// 약관 동의 변경
func toggleIsAgreed() {
isAgreed.toggle()
}
/// 약관 동의 리셋
func resetIsAgreed() {
isAgreed = false
}
/// 약관 동의 알럿
private func showTermsAgreeAlert() {
CommonUtil.showAlert(title: "이용 약관을 동의해주세요", message: nil, actionTitle: "확인", actionStyle: .default) { _ in return }
}
}
// **ViewController ======================================================**
class LoginVC: UIViewController {
@objc func tapGoogleButton() {
vm.**handleGoogleLogin**(with: self)
}
}