Created
December 2, 2019 18:13
-
-
Save Shehryar/e90516ca26d3a7ab925118a0b8697a70 to your computer and use it in GitHub Desktop.
Custom operator for creating a closed countable range from two Characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator ←→ | |
extension Character { | |
static func ←→(lhs: Character, rhs: Character) -> CountableClosedRange<UInt8> { | |
guard let lhsInt = lhs.asciiValue, let rhsInt = rhs.asciiValue else { | |
return 0...0 | |
} | |
return lhsInt...rhsInt | |
} | |
} | |
} | |
let range = "A"←→"Z" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment