Skip to content

Instantly share code, notes, and snippets.

@bill350
Last active October 26, 2018 10:18
Show Gist options
  • Save bill350/9a48a36a1b6aa6c3e78517f1b614da19 to your computer and use it in GitHub Desktop.
Save bill350/9a48a36a1b6aa6c3e78517f1b614da19 to your computer and use it in GitHub Desktop.
/// 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
}
}
}
@mrianmerry
Copy link

If placeholder is set in the initialiser, I don't think there's any need to provide a value at declaration time 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment