Skip to content

Commit 109a523

Browse files
authored
Update README.md (#20)
1 parent 7ac5014 commit 109a523

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ If you need to validate some data, you can use the `Validator` object for this p
3636
import ValidatorCore
3737

3838
let validator = Validator()
39-
let result = validator.validate(input: "text", rule: LengthValidationRule(min: 4, error: "error text"))
39+
let result = validator.validate(input: "text", rule: LengthValidationRule(min: 4, error: "Text must be at least 4 characters long"))
4040

4141
switch result {
4242
case .valid:
43-
print("text is valid")
43+
print("Text is valid")
4444
case let .invalid(errors):
4545
// handle validation errors
46-
print(errors)
46+
print("Validation errors: \(errors.map(\.message))")
4747
}
4848
```
4949

@@ -66,16 +66,16 @@ class ViewController: UIViewController {
6666
super.viewDidLoad()
6767

6868
/// Adds validation rule to the text field.
69-
textField.add(rule: LengthValidationRule(max: 10, error: "error text"))
69+
textField.add(rule: LengthValidationRule(max: 10, error: "Text must be at most 10 characters"))
7070
/// Enables automatic validation on input change.
7171
textField.validateOnInputChange(isEnabled: true)
7272
/// Handle the validation result.
7373
textField.validationHandler = { result in
7474
switch result {
7575
case .valid:
76-
print("text is valid")
76+
print("Text is valid")
7777
case let .invalid(errors):
78-
print(errors)
78+
print("Validation errors: \(errors)")
7979
}
8080
}
8181
}
@@ -122,14 +122,14 @@ struct ContentView: View {
122122
@State private var text: String = ""
123123

124124
private let validationRules: [any IValidationRule<String>] = [
125-
LengthValidationRule(max: 10, error: "Text error")
125+
LengthValidationRule(max: 10, error: "Text must be at most 10 characters")
126126
]
127127

128128
var body: some View {
129129
VStack {
130-
TextField("Text", text: $text)
130+
TextField("Enter text", text: $text)
131131
.validate(item: $text, rules: validationRules) { errors in
132-
Text("Text is bigger than 10 characters")
132+
Text("Text exceeds 10 characters")
133133
}
134134
}
135135
}
@@ -149,10 +149,10 @@ class Form: ObservableObject {
149149
@Published
150150
var manager = FormFieldManager()
151151

152-
@FormField(rules: [LengthValidationRule(max: 20, error: "The first name is very long")])
152+
@FormField(rules: [LengthValidationRule(max: 20, error: "First name is too long")])
153153
var firstName: String = ""
154154

155-
@FormField(rules: [LengthValidationRule(min: 5, error: "The last name is too short")])
155+
@FormField(rules: [LengthValidationRule(min: 5, error: "Last name is too short")])
156156
var lastName: String = ""
157157

158158
lazy var firstNameValidationContainer = _firstName.validate(manager: manager)
@@ -180,9 +180,9 @@ struct ContentView: View {
180180
form.manager.$isValid,
181181
perform: { value in
182182
if value {
183-
print("The form's fields are valid")
183+
print("All form fields are valid")
184184
} else {
185-
print("The form's fields aren't valid")
185+
print("Some form fields are invalid")
186186
}
187187
}
188188
)

0 commit comments

Comments
 (0)