RequiredRule

public class RequiredRule<V> : ValidationRule<V>

RequiredRule is a subclass of ValidationRule that means value can’t be nil or blank. Make sure required rule is the first item in rules list

  • Initializes a RequiredRule object that will validate a value is not nil.

    Declaration

    Swift

    public override init(message: String = "can not be blank.")

    Parameters

    message

    String of error message.

    Return Value

    An initialized RequiredRule object.

  • Method used to validate the provided value.

    Declaration

    Swift

    public override func validate(_ value: V?) -> String?

    Parameters

    value

    Any value to be checked for validation.

    Return Value

    Error Message. nil if validation is successful; String if validation fails. Returns error for empty string or collection