We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Observable<T> { var value: T { didSet { listener?(value) } } private var listener: ((T) -> Void)? init(_ value: T) { self.value = value } func bind(_ closure: @escaping (T) -> Void) { closure(value) listener = closure } }
class ViewModel { var username = Observable("고래밥") var password = Observable("") }
class ViewController { override func viewDidLoad() { viewmodel.username.bind { text in self.mainView.usernameTextField.text = text } viewmodel.password.bind { text in self.mainView.passwordTextField.text = text } } @objc func passwordTextFieldDidChange(_ textfield: UITextField) { viewmodel.password.value = textfield.text ?? "" } @objc func usernameTextFieldDidChange(_ textfield: UITextField) { viewmodel.username.value = textfield.text ?? "" } }
참고자료
The text was updated successfully, but these errors were encountered:
No branches or pull requests
MVVM
비지니스 로직 : 유저 눈에는 보이지 않지만, 유저가 바라는 결과물을 올바르게 도출할 수 있도록 짜여진 코드
Observable을 통한 데이터 바인딩
ViewModel
ViewController
참고자료
The text was updated successfully, but these errors were encountered: