Skip to content

Latest commit

 

History

History
39 lines (35 loc) · 1.6 KB

README.md

File metadata and controls

39 lines (35 loc) · 1.6 KB

ValidationExampleSwift Validation code using tuples and variadic parameters...

Variadic parameter example:-

func arithmeticMean(_ numbers: Double...) -> Double {
    var total: Double = 0
    for number in numbers {
        total += number
    }
return total / Double(numbers.count)
}
arithmeticMean(1, 2, 3, 4, 5)
// returns 3.0, which is the arithmetic mean of these five numbers
arithmeticMean(3, 8.25, 18.75)
// returns 10.0, which is the arithmetic mean of these three numbers

Usage Example of validation with three values

let response = Validation.shared.validate(values: (ValidationType.email, "[email protected]"), (ValidationType.phoneNo, "56545654654665"), (ValidationType.stringWithFirstLetterCaps, "tyh56gf"))
    switch response {
    case .success:
        break
    case .failure(_, let message):
        print(message.localized())
    }

only with two value validations

let response = Validation.shared.validate(values: (ValidationType.email, "[email protected]"), (ValidationType.stringWithFirstLetterCaps, "tyh56gf"))
    switch response {
    case .success:
        break
    case .failure(_, let message):
        print(message.localized())
    }