~= vs Range.contains(_:)

Today I was working on simple validators that we use for forms (backed by awesome Eureka) and had to implement validator that validates string length. So I did it like this: struct StringValidator: Validator { typealias ValueType = String let stringRange: Range<Int> init(stringRange: Range<Int> = 1..<Int.max) { self.stringRange = stringRange } func validate(value: String?) -> Bool { guard let value = value?.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet()) else { return true } return stringRange.contains(value.characters.count) } } The idea is simple. Form field can have a validator with default range (1..<Int.max) that will validate any not »