-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/#157 정규식에 따라 텍스트필드 상태 업데이트하는 ViewModel 바인딩
- Loading branch information
Showing
7 changed files
with
166 additions
and
41 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
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
42 changes: 42 additions & 0 deletions
42
KkuMulKum/Source/GroupCreate/ViewModel/InviteCodeViewModel.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,42 @@ | ||
// | ||
// InviteCodeViewModel.swift | ||
// KkuMulKum | ||
// | ||
// Created by YOUJIM on 7/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
enum InviteCodeState { | ||
case empty | ||
case selected | ||
case valid | ||
case invalid | ||
} | ||
|
||
class InviteCodeViewModel { | ||
let inviteCode = ObservablePattern<String>("") | ||
let inviteCodeState = ObservablePattern<InviteCodeState>(.empty) | ||
let codeErrorMessage = ObservablePattern<String?>(nil) | ||
let isNextButtonEnabled = ObservablePattern<Bool>(false) | ||
|
||
private let codeRegex = "{1,5}$" | ||
|
||
func validateCode(_ code: String) { | ||
inviteCode.value = code | ||
|
||
if code.isEmpty { | ||
inviteCodeState.value = .empty | ||
codeErrorMessage.value = nil | ||
isNextButtonEnabled.value = false | ||
} else if code.range(of: codeRegex, options: .regularExpression) != nil { | ||
inviteCodeState.value = .valid | ||
codeErrorMessage.value = nil | ||
isNextButtonEnabled.value = true | ||
} else { | ||
inviteCodeState.value = .invalid | ||
codeErrorMessage.value = "한글, 영문, 숫자만을 사용해 총 5자 이내로 입력해주세요." | ||
isNextButtonEnabled.value = false | ||
} | ||
} | ||
} |
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