Last active
October 26, 2018 10:18
-
-
Save bill350/9a48a36a1b6aa6c3e78517f1b614da19 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// ViewModel to display and react to text events, to update data | |
class FormItem: FormValidable { | |
var value: String? | |
var placeholder = "" | |
var indexPath: IndexPath? | |
var valueCompletion: ((String?) -> Void)? | |
var isMandatory = true | |
var isValid = true //FormValidable | |
var uiProperties = FormItemUIProperties() | |
// MARK: Init | |
init(placeholder: String, value: String? = nil) { | |
self.placeholder = placeholder | |
self.value = value | |
} | |
// MARK: FormValidable | |
func checkValidity() { | |
if self.isMandatory { | |
self.isValid = self.value != nil && self.value?.isEmpty == false | |
} else { | |
self.isValid = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If
placeholder
is set in the initialiser, I don't think there's any need to provide a value at declaration time 😉