Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Last active December 12, 2022 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/7f4681ad61f1fc943cf49ec940eb04de to your computer and use it in GitHub Desktop.
Save TuenTuenna/7f4681ad61f1fc943cf49ec940eb04de to your computer and use it in GitHub Desktop.
password check
import Foundation
import Combine

class TestVM : ObservableObject {
    
    
    @Published var password : String = ""
    
    @Published var checkPassword: String = ""
    
    lazy var isPasswordValid : AnyPublisher<Bool, Never> = Publishers.CombineLatest($password, $checkPassword).map { (password, checkPassword) in
        
        
        return true
    }.eraseToAnyPublisher()
    
    @Published var errMsg : String = ""
    
    var subscriptions = Set<AnyCancellable>()
    
    init(){
        
        Publishers.CombineLatest($password, $checkPassword).map({ (password, checkPassword) in
            
            if password == checkPassword {
                return "일치합니다"
            } else {
                return "일치하지 않습니다"
            }
        }) // String
        .eraseToAnyPublisher()
        .assign(to: errMsg, on: self)
        .store(in: &subscriptions)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment