// MARK: - 👀비밀번호 퍼블리셔
@Published var passWord: String = ""
// 비밀 번호 퍼블리셔
@Published var checkPassWord1: String = ""
@Published var checkPassWord2: String = ""
// 비밀번호 + 비밀번호 확인 일치여부
@Published var passwordAndPasswordCheckSame: Bool = false
// 비밀번호 + 비밀번호 확인 글자수 6~12 사이 여부
@Published var passwordAndPasswordCheckCountValid: Bool = false
// 비밀번호 유효성 최종 학인 여부
@Published var passwordValidCheck: Bool = true
// 비밀번호 입력한 것이 같은지
// 비밀번호 6자리 이상 ~ 12 자리 이하
// MARK: - 비밀번호 유효성 체크
func passwordTextFieldValidCheck() {
// 비밀번호 입력한 것이 같은지
Publishers.CombineLatest($checkPassWord1, $checkPassWord2)
.map { (password1, password2) in
if password1 != password2 {
return false
}
self.passWord += password2
return true
}
.assign(to: \.self.passwordAndPasswordCheckSame, on: self)
.store(in: &subscriptions)
// 비밀번호 6자리 이상 ~ 12 자리 이하
Publishers.CombineLatest($checkPassWord1, $checkPassWord2)
.map { (password1, password2) in
if (6...12).contains(password1.count) && (6...12).contains(password2.count) {
return true
} else {
return false
}
}
.assign(to: \.self.passwordAndPasswordCheckCountValid, on: self)
.store(in: &subscriptions)
// 여러가지 상태 스트림 합치기
Publishers.CombineLatest($passwordAndPasswordCheckSame, $passwordAndPasswordCheckCountValid)
.map { (checkSame, checkCountValid) in
if (checkSame == true && checkCountValid == true) {
return true
} else {
return false
}
}
.assign(to: \.self.passwordValidCheck, on: self)
.store(in: &subscriptions)
}
Created
December 12, 2022 20:25
-
-
Save hertz315/5ccbe6100b2e28f72b4b109e15c35476 to your computer and use it in GitHub Desktop.
회원가입 로직 - 비밀번호 유효성 체크 Combine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment