LengthPredicate
public struct LengthPredicate<T> : Predicate where T : Collection
The LengthPredicate
struct is used to evaluate whether a given input is of a given length.
let predicate = LengthPredicate<String>(8...64)
let isValid = predicate.evaluate(with: "p@ssW0rd")
-
Declaration
Swift
public typealias InputType = T
-
Returns a new
LengthPredicate
instance.let predicate = LengthPredicate<String>(min: 8, max: 64) let isValid = predicate.evaluate(with: "p@ssW0rd")
Declaration
Swift
public init(min: Int? = nil, max: Int? = nil)
Parameters
min
The lower bound of the range.
max
The upper bound of the range.
-
Creates and returns a new
LengthPredicate
instance.let predicate = LengthPredicate<String>(8...64) let isValid = predicate.evaluate(with: "p@ssW0rd")
Declaration
Swift
public init(_ range: ClosedRange<Int>)
Parameters
range
A
ClosedRange
that defines the lower and upper bounds of the range. -
Creates and returns a new
RangePredicate
instance.let predicate = LengthPredicate<String>(8..<65) let isValid = predicate.evaluate(with: "p@ssW0rd")
Declaration
Swift
public init(_ range: Range<Int>)
Parameters
range
A
Range
that defines the lower and upper bounds of the range. -
Returns a
Boolean
value that indicates whether a given input is inside the given range bounds.Declaration
Swift
public func evaluate(with input: T) -> Bool
Parameters
input
The input against which to evaluate the receiver.
Return Value
true
if input is between the range bounds, otherwisefalse
.