RangePredicate
public struct RangePredicate<T> : Predicate where T : Comparable
The RangePredicate
struct is used to evaluate whether a given input is inside a given range.
let drinkingAgeLimit = RangePredicate(min: 21)
let isAllowed = drinkingAgeLimit.evaluate(with: 18)
-
Declaration
Swift
public typealias InputType = T
-
Returns a new
RangePredicate
instance.let drinkingAgeLimit = RangePredicate(min: 21) let isAllowed = drinkingAgeLimit.evaluate(with: 18)
Declaration
Swift
public init(min: T? = nil, max: T? = nil)
Parameters
min
The lower bound of the range.
max
The upper bound of the range.
-
Returns a new
RangePredicate
instance.let predicate = RangePredicate(21...90) let isAllowed = predicate.evaluate(with: 25)
Declaration
Swift
public init(_ range: ClosedRange<T>)
Parameters
range
A
ClosedRange
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
.
-
Returns a new
RangePredicate
instance.let predicate = RangePredicate(21..<91) let isAllowed = predicate.evaluate(with: 25)
Declaration
Swift
public init(_ range: Range<T>)
Parameters
range
A
Range
that defines the lower and upper bounds of the range.