Swiftpack.co - pridees/combine-validate as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by pridees.
pridees/combine-validate 1.1.0
🚦 Validation library depends on SwiftUI & Combine. Reactive and fully customizable.
⭐️ 19
🕓 2 years ago
iOS macOS watchOS
.package(url: "https://github.com/pridees/combine-validate.git", from: "1.1.0")

CombineValidate

License Swift versions Platforms codecov Test And Coverage

What is CombineValidate?

Useful satellite for validation user inputs proposes for any SwiftUI architectures. (MVVM as basic reference)

Batteries:

  • SwiftUI native
  • Combine under the hood
  • Fully customizable
  • Validate simple fields for non empty values
  • Validate fields by predefined or your own regular expressions
  • Try input by multiple regex expressions and emerge up the result what is the regex got fired
  • Pass your own error messages
  • Localize error messages with custom localization table names
  • Use the wide validation extension library
  • Extend the set of validation possibilities as you want

Examples

Basic usage

Firstly you should define the validation publisher within your @Published property

class FormViewModel: ObservableObject {
    
    @Published var email = ""
    public lazy var emailValidator: ValidationPublisher = {
        $email.validateWithRegex(
            regex: RegularPattern.email,
            error: "Not email",
            tableName: nil
        )
    }()
}

Excellent! And then, call the validate view modifier from your SwiftUI Input

TextField("Should email", text: $viewModel.email)
        .validate(for: viewModel.emailValidator)

Enjoy!

Same steps you can apply to SecureField and Toggle.

CombineValidateExtended library

Useful set of validation publishers and regular expressions library. Validation for

  • any kind of credit card numbers
  • urls
  • hash tags
  • numbers
  • passwords
  • much more

Requirements

The CombineValidate dependes on the Combine reactive framework. Minimal requirements:

  • iOS 13
  • MacOS Catalina

Installation

Package installation occurs via SPM. Add package in your Xcode as dependency

Documentation

Look at here and explore documentation.

GitHub

link
Stars: 19
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.1.0
2 years ago

Flex and easy

For now you can use validation more flexible

Validate complex structures with map keypath field deriving

 public lazy var emailValidator: ValidationPublisher = {
      $person.map(\.email)
          .validateWithRegex(
              regex: RegularPattern.email,
              error: "Not email",
              tableName: nil
          )
  }()

call .validate from any view as you want

makeRowWithIconAndPrefix(icon: "icon_facebook", prefix: "facebook.com/") {
    TextField("Facebook", text: $viewModel.editedProfile.facebook)
}
.validate(for: viewModel.facebookValidator, configuration: .hintOnly)

Feel free to make your contribution!

Good luck!

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics